Provides a code to check the PHP form and check the effect.
function Validate ($value, $onoff =0, $type =3, $len =100, $msg = ' Fill in error ') {
if (Trim ($value)! = "") {//If there is content
if (!is_int ($len))
Exit ("");
Preg_match_all ("/[xa0-xff"?). /", $value, $arr); String length in Chinese and English mixed rows
$qswhLen _v=count ($arr [0]);
if ($qswhLen _v> $len)
{
Exit ("");
}
if ($type ==0) {//Type 0 Then check whether the data is a number
if (!eregi (' ^[0-9]+$ ', $value)) {
Exit ("");
}
}
else if ($type ==1) {//type 1 Then check whether the data is a letter
if (!eregi (' ^[a-za-z]+$ ', $value)) {
Exit ("");
}
}
else if ($type ==2) {//Type 2 Then check whether the data is Chinese
if (!eregi ("^[". Chr (0XA1). " -". Chr (0xff)." +$ ", $value)) {
Exit ("");
}
}
else if ($type ==3) {//Type 3 then check whether the data is letters and numbers
if (!eregi (' ^[0-9a-za-z]+$ ', $value)) {
Exit ("");
}
}
else if ($type ==4) {//Type 4 e-mail check
if (!eregi ("^[_.0-9a-za-z-]+@" ([0-9a-za-z_-]+.) +[a-za-z]$ ", $value)) {
Exit ("");
}
}
else if ($type ==5) {//Type 5, date format check
if (!eregi (' ^[1-2]{1}[0-9]{3}-[0-9]{2}-[0-9]{2} ', $value)) {
Exit ("");
}
}
else if ($type ==6) {//type 6 for ID number format check
if (!preg_match ('/(^ [d]{15}|[ d]{18}| [d] {17}x) $)/', $value)) {
Exit ("");
}
}
else if ($type ==7) {//Type 7 then phone number format check
if (!preg_match ("/^ ((D{3})) | ( d{3}-))? ((0d{2,3}) |0d{2,3}-)? [1-9]d{6,7}$/", $value)) {
Exit ("");
}
}
else if ($type ==8) {//type 8, ZIP code format check
if (!preg_match ("/^[1-9]d{5}$/", $value)) {
Exit ("");
}
}
else if ($type ==9) {//Type 9 URL address format check
if (!preg_match ("/^http://[a-za-z0-9]+.[ a-za-z0-9]+[/=?%-&_~ ' @[] ': +!] * ([^<> ""]) *$/", $value)) {
Exit ("");
}
}
else if ($type ==10) {//Type 10 is unlimited
}else{
echo "";
Exit
}
}else{
if ($onoff!=0) {
echo "";
Exit
}
}
}
http://www.bkjia.com/PHPjc/445048.html www.bkjia.com true http://www.bkjia.com/PHPjc/445048.html techarticle provides a code to check the PHP form and check the effect. function Validate ($value, $onoff =0, $type =3, $len =100, $msg = ' Fill in error ') {if (Trim ($value)! =) {//If there is a content if (!is_in ...