regular expression for letters, numbers and - _ .

Posted by Jorre on Stack Overflow See other posts from Stack Overflow or by Jorre
Published on 2010-06-12T12:23:19Z Indexed on 2010/06/12 12:33 UTC
Read the original article Hit count: 264

Filed under:

I'm having trouble checking in PHP if a value is is any of the following combinations

  • letters (upper or lowercase)
  • numbers (0-9)
  • underscore (_)
  • dash (-)
  • point (.)
  • no spaces! or other characters

a few examples:

  • OK: "screen123.css"
  • OK: "screen-new-file.css"
  • OK: "screen_new.js"
  • NOT OK: "screen new file.css"

I guess I need a regex for this, since I need to throw an error when a give string has other characters in it than the ones mentioned above.

© Stack Overflow or respective owner

Related posts about regex