PHP form validation corresponds to Jquery-validate plugin

Source: Internet
Author: User
Tags php form php form validation
This article is about PHP form validation corresponding to the Jquery-validate plug-in, has a certain reference value, now share to everyone, the need for friends can refer to


Direct code. If you do not understand the parameters, you can refer to the Jquery-validate plugin

Learning Recommendations:
"THINKPHP5 Classic case" http://www.kancloud.cn/duerhong/rumen/308144
thinkphp Elite Group: 536633782



<?php/**/namespace vendor\mylib;class dbvalidate{function __construct () {}//required function v_required ($value, $limit = True) {if ($limit) {if (Isset ($value) and!empty ($value)) {return true;} Else{return false;}}  Else{return true;} }//Mailbox Public Function V_email ($value, $limit =true) {if ($limit) {if ($this->is_email ($value)) {return true;} Else{return false;}} Else{return true;}} Mobile number Public Function V_mobile ($value, $limit =true) {if ($limit) {if ($this->is_mobile ($value)) {return true;} Else{return false;}} Else{return true;}} Urlpublic function V_url ($value, $limit =true) {if ($limit) {if ($this->is_url ($value)) {return true;} Else{return false;}} Else{return true;}} Whether the number public function V_number ($value, $limit =true) {if ($limit) {if (Is_numeric ($value)) {return true;} Else{return false;}} Else{return true;}} Whether the integer public function v_digits ($value, $limit =true) {if ($limit) {if (Is_digits ($value)) {return true;} Else{return false;}} Else{return true;}} Detect legal suffix Public Function v_accept ($value, $liMit=true) {$list =explode ('. ', $value), $ext =end ($list); $extdot = '. '. $ext, if ($limit = = $ext or $limit = = $extdot) {return true;} Else{return false;}}  The maximum length of the character is only judged English cannot verify the Chinese public Function v_maxlength ($value, $limit =true) {$len =strlen ($value);  if ($len <= $limit) {return true;  } else{return false; }}//minimum character length note only English, numeric.  Unable to verify the Chinese public Function v_minlength ($value, $limit =true) {$len =strlen ($value);  if ($len >= $limit) {return true;  } else{return false;  }}//input value length interval public function v_rangelength ($value, $limit =true) {$list =explode (', ', $limit);  $len =strlen ($value);  $min = $list [0];  $max = $list [1];  if ($len >= $min and $len <= $max) {return true;  } else{return false;  }}//input value interval function v_range ($value, $limit =true) {$list =explode (', ', $limit);  $min = $list [0];  $max = $list [1];  if ($value >= $min and $value <= $max) {return true;  } else{return false;  The maximum value of}}//input function V_max ($value, $limit =true) {if ($value <= $limit) {return true; } else{RetuRN false; }}//Input Minimum function v_min ($value, $limit =true) {if ($value >= $limit) {return true;} Else{return false;}} -------------------Public Authentication-----=========================--------//Whether the mailbox function Is_email ($email) {if (!filter_var ($ email, filter_validate_email)) {return false;} else {return true;}} Verify mobile number function Is_mobile ($STR) {if (Preg_match ("/1[3458]{1}\d{9}$/", $str)) {return true;} else{return false;}} Verify that the URL address function Is_url ($str) {return Preg_match ("/^http:\/\/[a-za-z0-9]+\.[ a-za-z0-9]+[\/=\?%\ -&_~ ' @[\]\ ': +!] * ([^<>\]) *$/", $str);}        function Is_date ($date) {//Match date format if (Preg_match ("/^ ([0-9]{4})-([0-9]{2})-([0-9]{2}) $/", $date, $parts)) {        Detects if is a date if (Checkdate ($parts [2], $parts [3], $parts [1])) {return true;        } else{return false;    }} else{return false; }}function is_digits ($STR) {if (Is_numeric ($STR)) {if (!strstr ($str, '. '))  {return true;    } else{return false; }} else{REturn false; }}//detection suffix explodepublic function is_ext ($str) {$file _list=explode ('. ');}}? >


Jquery-validate plug-in Parameters


Jqueryvalidation frequently used plugins * on behalf of PHP temporarily does not support required:true must be entered fields. Remote: "check.php" validates the input value using the Ajax method call check.php. Email:true must enter the correct format for the e-mail. Url:true must enter the URL in the correct format. Date:true must enter a date in the correct format. Date Check IE6 error, use with caution. Dateiso:true must enter the correct format for the date (ISO), for example: 2009-06-23, 1998/01/22. Verify the format only and do not validate the validity. Number:true must enter a valid number (negative, fractional). Digits:true must enter an integer. CreditCard: A valid credit card number must be entered. Equalto: The "#field" input value must be the same as #field. Accept: Enter a string with a legal suffix (the suffix of the uploaded file). Maxlength:5 Enter a string of up to 5 in length (Chinese characters are counted as one character). Minlength:10 enter a string with a minimum length of 10 (Chinese characters are counted as one character). RANGELENGTH:[5,10] Enter a string that must be between 5 and 10 (Chinese characters are counted as one character). RANGE:[5,10] Input values must be between 5 and 10. Max:5 input value cannot be greater than 5. Min:10 input value cannot be less than 10.
Related Article

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.