Pattern matching character:
\: Escape character For example: \b escapes b
^: Regular expression start symbol
$: regular expression end symbol
*: matches the previous character appearing 0 or n times
+: matches the previous character appearing 1 or n times
?: Matches the previous character 0 or 1 times
.: Matches all single characters except newlines
|: or means, for example, x|y matches x or y
{n}: matches the first n characters
{n,m}: matches at least n up to m previous characters
[xyz]: matches any character in the brackets
[^xyz]: matches any character except the brackets Characters are equivalent to [0-9]
\w: Match any number or letter or underscore, which is equivalent to [A-Za-z0-9_]
\d: Match any number between 0--9
Pattern modifier:
i: Ignore case
Examples of commonly used regular expressions:
//The user name consists of 6-18 digits of alphanumeric characters and underscores, and cannot begin with a number
var r_name=/^[a-z]\w {5,17}$/i
//The password length cannot be less than six characters
var r_pwd=/^\w{6,}$/
//All general email addresses
var r_eamil=/^\w+@\w+(\.)\w+$/
//Match a QQ email address
//861745122@qq.com
var r_qq_email=/^\d{5,}@qq(\.)com$/
//Match a 163 email address
var r_163_email=/^\w+@163(\.)com$/
//Match A suffix might be .com|.net|.cn|.edu
var email=/^\w+@\w+(\.)com|net|cn|edu$/
//Requires a valid age group
var r_age=/^\d{1,2}$/
//if (age>=18&&age《=100)
//Verify mobile phone number: 11 digits starting with 13 15 18
var r_tel=/^1[3,5, 8]\d{9}$/
//Verify the 18-digit or 17-digit ID number plus an X
var r_s=/^\d{18 }|\d{17}x$/i
//Verify Chinese var reg=/^[\u4e00-\u9fa5]{2,17}$/
//php
$reg = "/^[\x{4e00}-\x{9fa5}]$/u"
php regular verification
string(9) "刘伟超" ["uqq"]=> string(10) "1111111111" ["uemail"]=> string(12) "66555@qq.com" ["utel"]=> string(11) "15863162320" ["uinfo"]=> string(48) "地方开始放假开放活动健康的话概括" } empty($_POST["uname"])?$uname="":$uname=$_POST["uname"]; empty($_POST["uemail"])?$uemail="":$uemail=$_POST["uemail"]; empty($_POST["utel"])?$utel="":$utel=$_POST["utel"]; empty($_POST["uqq"])?$uqq="":$uqq=$_POST["uqq"]; empty($_POST["uinfo"])?$uinfo="":$uinfo=$_POST["uinfo"]; //验证姓名 $reg="/^[\x{4e00}-\x{9fa5}]{2,3}$/u"; if(!preg_match($reg,$uname)){ echo "用户名应该2-3个汉字";die; //header("refresh:1;url=form.html"); } //验证邮箱 $reg="/^(\w+@\w+(\.)com|net|cn)$/"; if(!preg_match($reg,$uemail)){ echo "邮箱必须含有@,且以com结尾";header("refresh:1;url=form.html"); die; } //验证座机号 $reg="/^\d{11}$/"; if(!preg_match($reg,$utel)){ echo "座机号以010-22222222格式";header("refresh:1;url=form.html"); die; } //验证QQ号 $reg="/^\d{5,11}$/"; if(!preg_match($reg,$uqq)){ echo "qq必须是5-11位纯数字";header("refresh:1;url=form.html"); die; } //验证简介 /*$reg="/^[\x{4e00}-\x{9fa5}]{10,100}\W+/u"; if(!preg_match($reg,$uinfo)){ echo "简介应该10-100个汉字";die; //header("refresh:1;url=form.html"); } */ //连接数据库 $link=mysql_connect('127.0.0.1','root','root')or die("连接失败"); //选择数据库 mysql_select_db('kaoshi',$link); //设置字符集 mysql_query("set names utf8"); //写sql语句 $sql="insert into zhuce(c_name,c_qq,c_email,c_tel,c_info) values('$uname','$uqq','$uemail','$utel','$uinfo')"; //echo $sql;die; $rel=mysql_query($sql); if($rel){ echo "注册成功";header("refresh:1;url=show.php"); }else{echo "注册失败";header("refresh:1;url=form.html");} ?>
The above is the Ajax and PHP regular expression verification form and verification code introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. . I would also like to thank you all for your support of the PHP Chinese website!
For more articles related to Ajax and PHP regular expression verification forms and verification codes, please pay attention to the PHP Chinese website!