Ajax and PHP Regular expression validation form and verification Code _php instance

Source: Internet
Author: User
Tags character set php regular expression account security

Pattern-matching characters:

\: Escape character example: \b escaped B

^: Regular expression Start symbol

$: Regular expression End symbol

*: Matches the preceding character to appear 0 times or n times

+: Match the preceding character to appear 1 times or n times

?: matches the preceding character appears 0 or 1 times

.: matches all single characters except line breaks

|: Or, for example, x|y matches x or y

{n}: matches the preceding n characters

{n,m}: matches at least n up to M preceding characters

[XYZ]: matches any one of the characters in the brackets

[^XYZ]: Match any one of the characters except in brackets is equivalent to [0-9]

\w: Matching any number or letter or underscore is equivalent to [a-za-z0-9_]

\d: Matches the number between any one 0--9

Pattern modifier:

I: Ignore case

Examples of common regular expressions:

The username is made up of 6-18-digit alphanumeric underscores and cannot be preceded by a number

var r_name=/^[a-z]\w{5,17}$/i

Password length must not be less than six digits

var r_pwd=/^\w{6,}$/

All the 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$/

Matching a suffix name may be. com|.net|.cn|.edu

var email=/^\w+@\w+ (\.) com|net|cn|edu$/

Required to enter a valid age section

var r_age=/^\d{1,2}$/

if (age>=18&&age "=100")

Verify mobile phone Number: 11 digits 13 15 18 Start

var r_tel=/^1[3,5,8]\d{9}$/

Verify ID number 18 digits or 17 digits 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"

<span style= "FONT-SIZE:24PX;" > Below is an example of:</span> <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">  
 

php Regular validation

<?php header ("Content-type:text/html;charset=utf8"); 
Var_dump ($_post);d ie; Array (5) {["uname"]=> string (9) "Liu Weishu" ["Uqq"]=> string (a) "1111111111" ["Uemail"]=> string (12) "66555@" Qq.com "[Utel"]=> string (one) "15863162320" ["Uinfo"]=> string (48) "Place to begin a holiday to open activity healthy words Summary"} 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"]; 
Verify name $reg = "/^[\x{4e00}-\x{9fa5}]{2,3}$/u"; 
if (!preg_match ($reg, $uname)) {echo "User name should be 2-3 characters";d ie; 
Header ("refresh:1;url=form.html"); //Verify Mailbox $reg = "/^ (\w+@\w+ (\.) 
COM|NET|CN) $/"; 
if (!preg_match ($reg, $uemail)) {echo mailbox must contain @ and end with COM; header ("refresh:1;url=form.html"); die; 
/Verify the landline number $reg = "/^\d{11}$/"; 
if (!preg_match ($reg, $utel)) {echo "landline number in 010-22222222 format"; Header ("refresh:1;url=form.html"); die; }//Verify QQ number 
$reg = "/^\d{5,11}$/"; 
if (!preg_match ($reg, $uqq)) {echo "QQ must be a 5-11-digit pure number"; Header ("refresh:1;url=form.html"); die; 
}//Authentication profile/* $reg = "/^[\x{4e00}-\x{9fa5}]{10,100}\w+/u"; 
if (!preg_match ($reg, $uinfo)) {echo "Introduction should be 10-100 Chinese characters";d ie; 
Header ("refresh:1;url=form.html"); 
///Connection Database $link =mysql_connect (' 127.0.0.1 ', ' root ', ' root ') or Die ("Connection failed"); 
Select Database mysql_select_db (' Kaoshi ', $link); 
Sets the character set mysql_query ("Set names UTF8"); Write SQL statements $sql = "INSERT into Zhuce (c_name,c_qq,c_email,c_tel,c_info) VALUES (' $uname ', ' $uqq ', ' $uemail ', ' $utel ', ' $ 
Uinfo ') "; 
echo $sql;d ie; 
$rel =mysql_query ($sql); 
if ($rel) {echo "registered successfully"; Header ("refresh:1;url=show.php"); 
}else{echo "registration failed"; Header ("refresh:1;url=form.html"); ?>

The above is a small series to introduce Ajax and PHP regular expression verification form and verification code, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.