This article example needs to verify the content: The mail address, the URL address, the telephone number, the postal code , the verification method share for everybody reference, the concrete content is as follows
1, the verification of the e-mail address
<?php/
* Verify email address/
function Checkmail ($email) {
//user name, by "\w" format character, "-" or "." Composed
$email _name= "\w| ( \w[-.\w]*\w) ";
The first paragraph in the domain name is similar to the rule and user name, excluding the dot number "."
$code _at= "@";
$per _domain= "\w| (\w[-\w]*\w) ";
The middle portion of the domain name, up to two paragraphs
$mid _domain= "(\.") $per _domain. ") {0,2}";
The last paragraph in the 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 are returned to the successful
Var_dump (Checkmail ("root@localhost"));
Var_dump (Checkmail ("Frank.Roulan@esun.edu.org"));
Var_dump (Checkmail ("Tom.024-1234@x-power_1980.mail-address.com"));
? >
2, the URL address of the check
<?php
/* Verify 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");/return True
?>
3. Telephone number
<?php
/* Verify phone number/
function Checktelno ($tel)
{
//Remove superfluous separator
$tel = ereg_replace ("[\ \] \. -] "," ", $tel);
Contains only numbers, at least one 6-bit telephone number (that is, no area code)
if (Ereg ("^\d+$", $tel))
{return
true;
} else{return
false;
}
$rs = Checktelno ("(086)-0411-12345678");/return True
?>
4. Check the ZIP code
<?php
/* Verify ZIP Code
/function Checkzipcode ($code)
{
//Remove superfluous separator
$code = preg_replace ("/[\. -]/"," ", $code);
Contains a 6-bit zip code
if (Preg_match ("/^\d{6}$/", $code))
{return
true;
} else{return
false;
}
$rs = Checkzipcode ("123456");/return True
?>
Hopefully this article will help you learn about PHP programming.