views:

62

answers:

3

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 az. 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
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
@kiamlaluno: Javascript Regex and Unicode... That would be crazy.
KennyTM
+2  A: 

^[a-z]+$ Will find one and only one lower-case word, with no spaces before or after the word.

Merlyn Morgan-Graham
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