Hey can anyone whip up a regex that i could use to validate strings containing only alphanumeric characters along with ' ', '-', '_', and '.' ?
Thanks
Hey can anyone whip up a regex that i could use to validate strings containing only alphanumeric characters along with ' ', '-', '_', and '.' ?
Thanks
/^[\w. -]*$/
The \w
predefined character class includes alphanumeric characters and underscores, and is shorter to type than a-zA-Z0-9_
Also, depending on whether you want to allow empty strings or not, you'll want to use either *
or +
.
@chaos or anyone else: I am just curious, where isn't \w and \d stuff supported. I use them in Perl and Ruby. I had the idea that they are supported by every language.