PHP Form Validation Code _php tutorial

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.