Ajax and PHP regular expressions are used to verify the form, verification code, and ajax regular expressions.

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

Ajax and PHP regular expressions are used to verify the form, verification code, and ajax regular expressions.

Pattern match:

\: Escape character, for example, \ B escaped B

^: Regular Expression start symbol

$: End symbol of the Regular Expression

*: Match the previous character 0 or n times

+: Match the previous character once or n times

? : Match the previous character 0 times or 1 time

.: Match all single characters except line breaks

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

{N}: match the previous n characters

{N, m}: match at least n to a maximum of m prefix characters

[Xyz]: match any character in brackets

[^ Xyz]: match any character except the brackets is equivalent to [0-9]

\ W: match any number, letter, or underline is equivalent to [A-Za-z0-9 _]

\ D: match any number between 0 and 9

Pattern modifier:

I: case insensitive

Examples of common Regular Expressions:

// The username consists of 6-18 digits, which cannot start 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 common 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 may be. com |. net |. cn |. edu

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

// Enter a valid age group

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

// If (age> = 18 & age & lt; = 100)

// Verification mobile phone number: 11-digit, 13-digit, 15-18

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

// Verify that the ID card number is 18 or 17 digits plus an X

Var r_s =/^ \ d {18} | \ d {17} x $/I

// Verify the Chinese var reg =/^ [\ u4e00-\ u9fa5] {2, 17} $/

// Php

$ Reg = "/^ [\ x {4e00}-\ x {9fa5}] $/u"

<Span style = "font-size: 24px;"> The following is an example: </span> <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

Php Regular Expression Verification

<? Php header ("content-type: text/html; charset = utf8"); // var_dump ($ _ POST); die; // array (5) {["uname"] => string (9) "Liu weichao" ["uqq"] => string (10) "1111111111" ["uemail"] => string (12) "66555@qq.com" ["utel"] => string (11) "15863162320" ["uinfo"] => string (48) "Summary of healthy local open holidays"} 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 the name $ reg = "/^ [\ x {4e00}-\ x {9fa5}] {2, 3} $/u"; if (! Preg_match ($ reg, $ uname) {echo "the user name should have 2-3 Chinese characters"; die; // header ("refresh: 1#url#form.html ");} // verify email address $ reg = "/^ (\ w + @ \ w + (\.) com | net | cn) $/"; if (! Preg_match ($ reg, $ uemail) {echo "the email must contain @ and end with com"; header ("refresh: 110000url0000form.html"); die ;} // verify the landline number $ reg = "/^ \ d {11} $/"; if (! Preg_match ($ reg, $ utel) {echo "landline number in 010-22222222 format"; header ("refresh: 110000url0000form.html"); die ;} // verify QQ No. $ reg = "/^ \ d {5, 11} $/"; if (! Preg_match ($ reg, $ uqq) {echo "qq must be a 5-11-bit pure number"; header ("refresh: 110000url0000form.html"); die ;} // verification Overview/* $ reg = "/^ [\ x {4e00}-\ x {9fa5}] {10,100} \ W +/u"; if (! Preg_match ($ reg, $ uinfo) {echo "introduction should contain 10-Chinese characters"; die; // header ("refresh: 110000url0000form.html ");} * // connect to the database $ link = mysql_connect ('2017. 0.0.1 ', 'root', 'root') or die ("connection failed"); // select the database mysql_select_db ('aoshi', $ link ); // set the character set mysql_query ("set names utf8"); // write an SQL statement $ 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 ($ sq L); if ($ rel) {echo "registered successfully"; header ("refresh: 1; url = show. php ");} else {echo" registration failed "; header (" refresh: 110000url0000form.html ") ;}?>

The above section describes the Ajax and PHP Regular Expression verification forms and verification codes. I hope this will help you. If you have any questions, please leave a message for me, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!

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.