preg_match() and username(Preg_Match()和用户名)
本文介绍了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
这篇关于Preg_Match()和用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!