Preg_Match()和用户名
function isUserID($username) {
if (preg_match('/^[a-zd_]{2,20}$/i', $username)) {
return true;
} else {
return false;
}
}
简单的一个..,我有这个,你能解释一下它检查什么吗?我知道它会检查用户名的长度是否在2-20之间,还有什么?谢谢
解决方案
它搜索仅包含字母数字和下划线字符的文本,长度为2到20个字符。
/^[a-zd_]{2,20}$/i
|||| | ||| |||
|||| | ||| ||i : case insensitive
|||| | ||| |/ : end of regex
|||| | ||| $ : end of text
|||| | ||{2,20} : repeated 2 to 20 times
|||| | |] : end character group
|||| | _ : underscore
|||| d : any digit
|||a-z: 'a' through 'z'
||[ : start character group
|^ : beginning of text
/ : regex start
相关文章