Home > Backend Development > PHP Tutorial > Preg_match username regular example in php_PHP tutorial

Preg_match username regular example in php_PHP tutorial

WBOY
Release: 2016-07-13 10:36:17
Original
1155 people have browsed it

Examples, letters, numbers and Chinese characters

The code is as follows
 代码如下
if(preg_match("/[ '.,:;*?~`!@#$%^&+=)(<>{}]|]|[|/||"||/",$user)){
echo '不要在名字里面整些特殊符号,请只使用字母、数字和汉字,当然要你的浏览器要选简体中文GB2312哟,千万不要选繁体、中文HZ等。返回修改后,再来,我等你哟!';
exit();
}
if(preg_match("/[ '.,:;*?~`!@#$%^&+=)(<>{}]|]|[|/||"||/" ,$user)){
echo 'Do not include special symbols in the name. Please only use letters, numbers and Chinese characters. Of course, your browser must select Simplified Chinese GB2312. Do not select Traditional or Chinese. HZ wait. Come back after modification, I'll wait for you! ';
exit();
}

Example, full letters
 代码如下

if (mb_ereg("^[w-.]{1,32}$", $str)) {
echo 'yes';
} else {
echo 'no http://www.111cn.net/';
}

?>

The code is as follows

if (mb_ereg("^[w-.]{1,32}$", $str)) {
echo 'yes';
} else {
echo 'no http://www.111cn.net/';
}

代码如下
?>

Attached are some commonly used regular rules
 代码如下

Can only start and end with numbers or letters. The username must be 4 to 18 characters in length

utf-8下
preg_match("/^[a-z0-9_x80-xff]+[^_]$/g",$a);
gbk下:
preg_match("/^[a-z0-9_".chr(0xa1)."-".chr(0xff)."]+[^_]$/",$a)
 代码如下

The user name is an uppercase letter, lowercase letter or underscore, and starts with a letter, and the length is 6-20

 代码如下
    Username: includes English lowercase, Chinese characters, numbers, and underscores. It cannot be all numbers and the underscore cannot be at the end
  • Chinese username verification is available
  • ​ Articles you may be interested in
  • php username regular expression, including Chinese, length 4-16 characters
  • Verify email format username url php regular expression
  • php username regular expression (Chinese, English, numbers, letters)
  • Number and letter regular expression (username verification)
  • php regular code to verify username legitimacy
php common regular expressions email username password ip html tag

preg_match regular expression to determine username

http://www.bkjia.com/PHPjc/739851.htmlwww.bkjia.comtrue
http: //www.bkjia.com/PHPjc/739851.htmlTechArticle
Example, the letters, numbers and Chinese character codes are as follows if(preg_match("/[ '.,:;*?~ `!@#$%^+=)({}]|]|[|/||"||/",$user)){ echo 'Do not include special symbols in the name, please only use letters and numbers ...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template