Wed validation of regular Expressions application (40)

Source: Internet
Author: User
Tags ereg
Verification of e-mail addresses

 Php/*Verify Email address*/function Checkmail ($email) {//user name, by "\w" format character, "-" or "." Composition$email _name="\w| (\w[-.\w]*\w)";//The first paragraph in the domain name, similar to the rule and user name, does not include the dot number "."$code _at="@"; $per _domain="\w| (\w[-\w]*\w)";//the middle part of the domain name, up to two paragraphs$mid _domain="(\.". $per _domain.") {0,2}";//The last paragraph of a domain name can only be ". com", ". org", or ". NET"$end _domain="(\.( com|net|org))"; $rs=Preg_match ("/^{$email _name}@{$per _domain}{$mid _domain}{$end _domain}$/", $email);return(BOOL) $rs;}//test, the following returns the successVar_dump (Checkmail ("root@localhost")); Var_dump (Checkmail ("Frank.Roulan@esun.edu.org")); Var_dump (Checkmail ("Tom.024-1234@x-power_1980.mail-address.com") );?>

The checksum of the URL address

 
  PHP/*  Check URL address */function Checkdomain ($domain) {return ereg ( " ^ (http|ftp) s?://(www\.)?. + (com|net|org) $", $domain);} $rs= Checkdomain ("www.taodoor.com"); // return false $rs = Checkdomain ("http://www.taodoor.com"); // back to True ?>

Phone number

 
  PHP/*  Verify phone number */function Checktelno ($tel) {// remove extra delimiter $tel = Ereg_replace ("[\ \) \. -]"" ", $tel); // contains only numbers, which should be at least one 6-bit phone number (i.e. no area code) if (Ereg ("^\d+$", $tel)) {returntrue;} Else {returnfalse;}} $rs= Checktelno ("(086) -0411-12345678"); // back to True ?>

Check for ZIP code

 
  PHP/*  Check Postal code */function Checkzipcode ($code) {// Remove extra separators $code = Preg_replace ("/[\. -]/"" ", $code); // contains a 6-bit zip code if (Preg_match ("/^\d{6}$/", $code)) {returntrue ;} Else {returnfalse;}} $rs= Checkzipcode ("123456"); // back to True ?>

The above describes the regular expression of the Wed validation application (40), including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.