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 Az 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?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.