Ajax and PHP regular expression verification form and verification code

Source: Internet
Author: User
This article mainly introduces information about Ajax and PHP regular expression verification forms and verification codes. it is very good and has reference value. if you need it, you can refer to the following pattern matching characters:

\: 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"

The following is an example:   
   
Related Article

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.