PHP Tutorial Chinese Characters Alphanumeric Underlined Regular Expressions
Regular expression matching whitespace characters: ^ s * | s * $
Commentary: Can be used to delete the first line of the first line of the whitespace characters (including spaces, tabs, page breaks, etc.), a very useful expression
$ action = trim ($ _ get ['action']);
if ($ action == "sub")
{
$ str = $ _post ['dir'];
//if(!preg_match("/^[".chr(0a1)."-".chr(0ff)."a-za-z0-9_]+$/",$str)) // gb2312 Chinese character letters Number underlined regular expression
if (! preg_match ("/ ^ [x {4e00} -x {9fa5} a-za-z0-9 _] + $ / u", $ str)) // utf-8 Kanji alphanumeric underscore Regular expression
{
echo "<font color = red> The typed [". $ str. "] you entered contains an illegal character </ font>";
}
else
{
echo "<font color = green> The typed [". $ str. "] you entered is perfectly legal, via! </ font>";
}
}
?>
<form method = "post" action = "">
Enter characters (numbers, letters, Chinese characters, underline):
<input type = "text" name = "dir" value = "">
<input type = "submit" value = "Submit">
</ form>
The regular expression matching url url: [a-za-z] +: // [^ s] *
Commentary: The function of the online version is very limited, the above can meet the needs of the basic match account is legitimate (the beginning of the letter, allowing 5-16 bytes, allowing the alphanumeric underscore): ^ [a-za- z0-9 _] {4,15} $
Commentary: Form validation is very useful when matching domestic phone numbers: d {3} -d {8} | d {4} -d {7}
Commentary: Matches such as 0511-4405222 or 021-87888822
Match Tencent qq number: [1-9] [0-9] {4,}
Commentary: Tencent qq number starting from 10000 match China Post Code: [1-9] d {5} (?! d)
Commentary: China postal code is 6 digits matching ID: d {15} | d {18}
Commentary: China's ID card for 15 or 18 match ip address: d +. D +. D +. D +
Commentary: Useful when extracting ip addresses