A regular expression is collected. You can verify that you can only enter numbers, Chinese characters, and English. Separate validation can also be integrated together to verify. But I was torn apart. better. can be verified separately. After my test can be used Oh! The following is the PHP validation can only input Chinese characters, English, digital code
<?php
if (Preg_match ('/^[0-9]+$/', $str)) {
Echo ' value can enter number ';
}
if (Preg_match ('/^[a-za-z]+$/', $str)) {
Echo ' can only be entered in English ';
}
Verify Chinese
Utf-8 under
Preg_match ("/^[a-z0-9_x80-xff]+[^_]$/g", $a);
if (Preg_match ("/^[\x7f-\xff]+$/", $str)) {
Echo ' can only input Chinese ';
}
GBK under:
Preg_match ("/^[a-z0-9_". Chr (0XA1). " -". Chr (0xFF)."] +[^_]$/", $a)
?>
Example
?
function Checkstr ($STR) {
$output = ';
$a =ereg (' [Chr 0xa1 '). -'. Chr (0xff). '] ', $str);
$b =ereg (' [0-9] ', $str);
$c =ereg (' [a-za-z] ', $str);
if ($a && $b && $c) {$output = ' mixed string ' in Chinese character digital English;}
ElseIf ($a && $b &&! $c) {$output = ' mixed string of kanji numbers ';}
ElseIf ($a &&! $b && $c) {$output = ' mixed string ' in English characters ';}
ElseIf (! $a && $b && $c) {$output = ' mixed string in digital English ';}
ElseIf ($a && $b &&! $c) {$output = ' pure Chinese ';}
ElseIf (! $a && $b &&! $c) {$output = ' pure number ';}
ElseIf (! $a && $b && $c) {$output = ' plain English ';}
return $output;
}
Example
PHP regular match numbers, Chinese and English, middle horizontal, underline, utf-8
Function check_string ($nickname) {
$nickname = Trim ($nickname);
& nbsp; $pattern = "# ([0-9a-za-z-_x{4e00}-x{9fa5}]+) #iu";
if (empty ($nickname) | |!preg_match ($pattern, $nickname)) {
return FALSE;
}
if (strlen $nickname) < 4 | | strlen ($NICKNAME) >) {
&NBSP;&NB sp; return FALSE;
}
return TRUE;
}