Provides a code for checking PHP form verification and checking effects.
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("");
('^[0-9]+$', $value)){
exit("") ;
}
}
else if ($type==2){ //If type is 2, check whether the data is Chinese
if(!eregi("^[".chr(0xa1) ."-".chr(0xff)."]+$",$value)){
exit("");
}
}
else if ($type==3){ //If the type is 3, check whether the data is letters and numbers
if( !eregi('^[0-9a-zA-Z]+$',$value)){
exit("");
}
}
else if ($type==4){ //If the type is 4, email check
if(!eregi( "^[_.0-9a-zA-Z-]+@([0-9a-zA-Z_-]+.)+[a-zA-Z]$", $value)){
exit ("");
=5){ //If the type is 5, date format check
if(!eregi('^[1-2]{1}[0-9]{3}-[0-9]{2}-[ 0-9]{2}',$value)){
exit("") ;
}
}
else if ($type==6){ //If the type is 6, ID card number format check
if(!preg_match('/(^([d]{ 15}|[d]{18}|[d]{17}x)$)/',$value)){
exit("");
}
}
else if ($type==7){ //If the type is 7, 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){ //If the type is 8, postcode format check
if(!preg_match(" /^[1-9]d{5}$/",$value)){
exit("");
}
}
else if ($type==10){ //If the type is 10, there is no limit
}else{
echo "";
exit;
}
{
if($onoff!=0){
echo "