I am looking for a regex pattern that ensures the user puts in a single lower case word with only letters of the alphabet. Basically they are picking a subdomain. Thanks in advance
+5
A:
The character class [a-z]
describes one single character of the alphabet of lowercase letters a
–z
. If you want if an input does only contain characters of that class, use this:
^[a-z]+$
^
and $
mark the start and end of the string respectively. And the quantifier +
allows one or more repetitions of the preceding expression.
Gumbo
2010-08-08 11:22:21
Without any further detail, this is the first answer I would think of. If the OP would report if he needs to match any Unicode letter, the answer could be expanded.
kiamlaluno
2010-08-08 11:24:57
@kiamlaluno: Javascript Regex and Unicode... That would be crazy.
KennyTM
2010-08-08 11:42:45
+2
A:
^[a-z]+$ Will find one and only one lower-case word, with no spaces before or after the word.
Merlyn Morgan-Graham
2010-08-08 11:24:15
A:
/^[a-z]+$/
make sure you aren't using 'i' after the last slash
/[a-z]+/
if you are searching for any words within the context
Alex V
2010-08-08 15:17:32