A solid nickname regexp
Posted
by iBram
on Stack Overflow
See other posts from Stack Overflow
or by iBram
Published on 2010-04-08T11:33:54Z
Indexed on
2010/04/08
11:43 UTC
Read the original article
Hit count: 381
I want a regular expression to validate a nickname: 6 to 36 characters, it should contain at least one letter. Other allowed characters: 0-9 and underscores.
This is what I have now:
if(!preg_match('/^.*(?=\d{0,})(?=[a-zA-Z]{1,})(?=[a-zA-Z0-9_]{6,36}).*$/i', $value)){
echo 'bad';
}
else{
echo 'good';
}
This seems to work, but when a validate this strings for example:
11111111111a > is not valid, but it should aaaaaaa!aaaa > is valid, but it shouldn't
Any ideas to make this regexp better?
© Stack Overflow or respective owner