thinkphp-Automatic Verification

Source: Internet
Author: User

Home or Home2\controller edit under the

/*//static verification
Automatic validation
$user =d (' Sks ');
$data [' name ']= ' 1234 ';
$data [' Pass ']= ' xxx ';
$data [' name2 ']= ' xxx ';
if ($user->create ($data)) {

Echo ' <br> ';
Echo ' All data success ';
}
else{
Output error message

Echo ' <br> ';
Echo ' <pre> ';
Var_dump ($user->geterror ());
Echo ' </pre> ';
}
*/


/*//Dynamic Validation
$rules =array (
Array (' name ', ' Require ', ' user name must not be null '),
);
$user =m (' Sks ');
$data [' name ']= ' 1234 ';
if ($user->validate ($rules)->create ($data)) {

Echo ' <br> ';
Echo ' All data success ';
}
else{
Output error message

Echo ' <br> ';
Echo ' <pre> ';
Var_dump ($user->geterror ());
Echo ' </pre> ';
}
*/

Home or Home2\model under the

protected $patchValidate =true;
If there are multiple errors, only one is shown, but this will make them all appear
Protected $_validate=array (
Field names, validation rules, error prompts, validation criteria, additional rules, validation time

Array (' name ', ' Require ', ' user must not be empty ', ' 0 ', ' regex ', ' 3 '),

Name field, not empty, error: On, (existence field on validation, attach rule, add or modify when validation) default item

Array (' name ', ' email ', ' mailbox '),

Array (' name ', ' url ', ' url '),

Array (' name ', ' Currency ', ' currency '),

Array (' name ', ' Zip ', ' postcode '),

Array (' name ', ' number ', ' positive integer '),

Array (' name ', ' Integer ', ' integers '),

Array (' name ', ' Double ', ' floating point '),

Array (' name ', ' 中文版 ', ' plain English '),


Additional rules-no built-in rules, self-determined rules

Array (' name ', '/^\d{3,6}$/', ' 3-6 digits ', 0, ' regex '),
Verifying 3-6-bit numbers

Array (' name ', ' xxx ', ' value not equal ', 0, ' equal '),
Verify that the specified value is equal

Array (' Pass ', ' xxx ', ' value cannot be equal ', 0, ' notequal '),
Verify that the specified value is not equal

Array (' name ', ' name2 ', ' two usernames different ', 0, ' confirm '),
Verify that two fields are equal

Array (' name ', array (+/-), ' not specified value ', 0, ' in '),
Array (' name ', ' Zhang San, John Doe, Harry ', ' not specified value ', 0, ' in '),
Verifies whether a value is a specified number

Array (' name ', array (1,3), ' must not be a specified value ', 0, ' notin '),
Array (' name ', ' Zhang San, John Doe, Harry ', ' must not be a specified value ', 0, ' notin '),
Verifies whether the value is not a specified number

Array (' Name ', ' 3 ', ' Please enter three digits ', 0, ' length '),
Array (' name ', ' 3,5 ', ' must not be less than three bits, not greater than five bits ', 0, ' length '),
Verify the number of digits in a number

Array (' name ', array (3,5), ' not within specified range ', 0, ' between '),
Array (' name ', ' 3,5 ', ' not within the specified range ', 0, ' between '),
Verify the number of digits in a number

Array (' name ', array (3,5), ' must not be within the specified range ', 0, ' Notbetween '),
Array (' name ', ' 3,5 ', ' must not be within the specified range ', 0, ' Notbetween '),
Verify the number of digits in a number

Array (' name ', ' 2017-4-10,2017-4-13 ', ' expired ', 0, ' expire '),
Set validity range, must be form submit valid, can be timestamp

Array (' name ', ' 192.168.0.10 ', ' current IP is forbidden ', 0, ' Ip_deny '),
Disable IP Access

Array (' name ', ' 127.0.0.1 ', ' current IP not allowed ', 0, ' Ip_allow '),
Allow only this IP access

Array (' name ', ' checklength ', ' username must be 3-5 bits ', 0, ' callback ', 3,array (3,5)),
Use callback Form

Array (' name ', ' checklength ', ' username must be 3-5 bits ', 0, ' callback ', 3,array (3,5)),
Use function form

);
/*//checklength callback Form
protected function Checklength ($STR, $min, $max) {
Preg_match_all ("/./u", $str, $matches);
$len =count ($matches [0]);
if ($len < $min | | $len > $max) {
return false;
}
else{
return true;
}
}
*/

thinkphp-Automatic Verification

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.