Form Field validation help (can’t get the regex right)
This is an open discussion with 6 replies, filed under General.
Search
Does the following work?
^\w+$
@designermonkey Nope, it appears to be, functionally, the same as [A-Za-z]. It can cope with cafe not café. Or Çelik.
Ok. If you want to match words, whatever character, and only one word then try the following...
^\S+$
This matches beginning and end of string, with one or more character that isn't a space, so one single string.
Hope it helps.
PS, intrigued that the first didn't match. Back to the reading books for me on unicode then ;o)
@designermonkey Thanks! That did the business. I need re-read “Mastering Regular Expressions.”
I actually hate this one, but this is quite good at testing regular (perl) expressions and it's free, There's also a desktop (air) application.
Useful resource there Thomas, thanks.
I use Patterns on the Mac.
Create an account or sign in to comment.
I am struggling to figure out how to construct a field validation to limit the value input to one word.
This should be simple except that I haven’t been able figure out away to parse out the spaces or punctuation.
[A-Za-z]+ will work for vanilla English but leaves out a range of characters that make up word in the broader sense such as é, Ø, Ì, æ, û, ý, Ç — etc. It seems that I need to use a positive regex (this is what I want, not this is what I don’t want)
Any wisdom? If I have to I’ll settle for just ensuring spaces are caught, but I can’t even do that :-(