PHP common Form Validation Regular expression _ regular expression

Source: Internet
Author: User
Tags chr


function Is_email ($STR) {
Check Email
Return Preg_match ("/^\w+ [-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) *$/", $str);
}

function Is_url ($STR) {
Check the Web site
Return Preg_match ("/^http:\/\/[a-za-z0-9]+\.[ a-za-z0-9]+[\/=\?%\ -&_~ ' @[\]\ ': +!] * ([^<>\ "])

*$/", $STR);
}

function Is_qq ($STR) {

Test QQ
Return Preg_match ("/^[1-9]\d{4,8}$/", $str);
}

function Is_zip ($STR) {

Inspection ZIP Code
Return Preg_match ("/^[1-9]\d{5}$/", $str);
}

function Is_idcard ($STR) {

Test ID
Return Preg_match ("/^\d{15} (\d{2}[a-za-z0-9])" $/", $str);
}

function Is_chinese ($STR) {

Test whether it is Chinese
Return Ereg ("^[". Chr (0XA1). " -". Chr (0xFF)."] +$ ", $STR);
}

function Is_english ($STR) {

Whether the test is English
Return Preg_match ("/^[a-za-z]+$/", $str);
}

function Is_mobile ($STR) {

Check if it's a cell phone.
Return Preg_match (/^ (\d{3}\) | ( \d{3}\-))? 13\d{9}$/", $STR);
}

function Is_phone ($STR) {

Jianyun, is that a phone call?
Return Preg_match (/^ (\d{3}\) | ( \d{3}\-))? (\ (0\d{2,3}\) |0\d{2,3}-)? [1-9]\d{6,7}$/",

$STR);
}

function Is_safe ($STR) {
Return (Preg_match ("/^" ([a-z]*|[ a-z]*|\d*| [-_\~!@#\$%\^&\*\.\ (\) \[\]\{\}<>\?\\\/\ ' \ "]*) |.

{0,5}) $|\s/", $str)!= 0);
}
}

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.