<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> mobile phone number regular expression instance </title>
</Head>
<Body>
<Form id = "111 cnNet" name = "111 cnNet" method = "post" action = "">
<Input name = "url" type = "text"/>
<Input name = "" type = "submit" value = "submit"/>
</Form>
Enter 13875998850
Output valid contact information
Enter 0136986 + 9557
The output contact information is incorrect.
</Body>
</Html>
<?
Function funcPhone ($ str) // call number regular expression test
{
Return (preg_match ("/^ (d {3}) | (d {3 }-))? (0d {2, 3}) | 0d {2, 3 }-)? [1-9] d {6, 8} $/", $ str ))? True: false;
}
Function funcMtel ($ str) // phone number regular expression test
{
Return (preg_match ("/(? : 13d {1} | 15 [03689]) d {8} $/", $ str ))? True: false;
}
If ($ _ POST)
{
If (funcPhone ($ _ POST ['URL']) | funcMtel ($ _ POST ['URL'])
{
Echo 'valid contact information ';
}
Else
{
Exit ('problem with contact information ');
}
}
?>