I’m trying to do regular expression in PHP but I keep getting bugged. I want it so it’s A-Z, 0-9, and the underscore (_) but the underscore cannot be used on the edges of a text. Only on the inside.
Here is waht I have:
if (!ereg("^[a-zA-Z0-9_]{3,16}$",$username)) {
// Does not match
}else{
// Good job, within rules!
}
I’m not sure if this is the best way to do it, but it should work:
I decreased your bounds by
2because you are accounting for two characters at the beginning/end of the string.