[英]Regex only allow alphanumeric and at least two characters
I am using PHP and have a string that I need to validate that must be... 我正在使用PHP,并且需要验证的字符串必须是...
I have what I think is the correct regex for only Az and 0-9 which is... 我有我认为仅适用于Az和0-9的正确正则表达式是...
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.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.