Reputation: 12598
I am using PHP and have a string that I need to validate that must be...
I have what I think is the correct regex for only A-z and 0-9 which is...
if(preg_match('/[^a-z_\-0-9]/i', $string))
{
echo "not valid string";
}
but how do I add to this to also ensure that it is at least two characters long?
Upvotes: 2
Views: 3360
Reputation: 28993
I would look at
^[a-zA-Z0-9]{2,}$
start string, any character in a-z or A-Z or 0-9, matched two or more times, end string.
Upvotes: 1