VailData data verification

Source: Internet
Author: User
Provides various official and user-released code examples. For code reference, you are welcome to learn more. The VailData data verification class is used for server-side (PHP) Verification to verify the legitimacy of incoming data values, which is easy to use.
VailData verification class, plug-in
Note:
The VailData verification class provides built-in functions such as 'A', 'E', 'F', 's', 'n', 'R', 'Q', and 'T ', 'P', 'U'
Function a: determines whether it is null.
E function: verify Email
F function: judge whether two values are equal
R function: Regular Expression Verification
Q function: Verify qq
T function: Verify mobile phone number
P function: verification phone number
U function: Verify url

The rules are as follows:
S function:
S1-10 representation: Must be string type and between 1-10 Characters
S1, indicating that the string type must be at least one character
S10: the string type and length must be equal to 10 characters.

N function:
Functions n and s use the same method, but the difference is that the function is used to determine whether it is a numeric type.

E function:
E function no additional parameter type such as: e1-10, e10, e10, are all wrong

F function:
To determine whether the two values are equal, only the form name or array key names such as, password and password can be provided for confirmation.
Form: password, repeat_password
You can use the f function. Password => array (frepeat_password, 'the password and password are inconsistent !!! ');R function:
Use any regular expression
If user name verification must start with a letter 'Username' => array ('R/[a-z] [\ w]/I ', 'username format is incorrect !!! ');Q function, t function, p function, u function:
It has no special significance. The example is as follows: Qq => array ('Q', 'incorrect QQ number format ');
Tel => array ('T', 'incorrect Mobile Phone Number Format ');
Phone => array ('P', 'incorrect phone format ');
Url => array ('U', 'url format incorrect ');
The VailData function can execute simple logic judgment such:
Verify whether it is an email with a length of more than 10 Characters
Then the verification rule is 'Email '=> array ('e & s10,', 'email format is incorrect !!! ');Verification can be a phone number or a mobile phone number 'tel_phone'=>array('t|p')Special Verification (examples may not be appropriate) 'Test' => array ('e & s10, | n10', 'test format incorrect ');The preceding example shows that
The Email type must be 10 or more digits and 10 digits.

In addition, the VailData verification class can also pass in user-defined functions or enhance the scalability of the VailData verification class such:
However, functions and methods must comply with the following specifications:
1. Only true or false values can be returned, or a string value can be returned, but VailData will be processed as a boolean value.
2. You must bind a parameter, such
You need to verify whether the value is equal to the value you passed in, you must use the following format function($string,$eqVal) {
return $string == $eqVal;
}
This is $ string. The value is automatically assigned by VailData,

Reference class B{
public function test_eq($string,$eq_val) {
return $string === $eq_val;
}
}
Verification rules
Require B. class. php; 'Test' => array (new B (), 'test _ eq ', parameter 1, parameter 2,..., 'error message ');Note: The parameter passed here starts from $ eq_val, $ string, which is automatically passed in by VailData.

Example of common function input
Functions. php function test($string,$eq_val) {
return $string === $eq_val;
}
'Test' => array ('_ test', parameter 1, parameter 2,..., 'error message ');// The external function is identified,
Like the method, the parameter passed here starts from $ eq_val, $ string, and is automatically passed in by VailData.

If the verification fails, use the following method to determine if(!$b['vail_status']) parent::error($b['vail_error']);// For details, refer to the example
If it succeeds, it will return the array you previously passed in

The following is an example: If (isset ($ _ POST ['send']) {
$ PostData = VailData: _ vailData ()-> _ check (array (
'Username' => array ('s6-10 | n6-10 | r/^ [1] {3} $/| s5, ', 'username format incorrect '),
'Password' => array ('s10 | A', 'incorrect password format '),
'Repeat _ password' => array ('fpassword | n10, ', 'incorrect password validation format '),
'Email '=> array ('e & s10, | n10,', 'incorrect email format '),
'Remark' => array ('n10 & s10', 'Remarks cannot be blank '),
'Phone' => array ('s10, ',' the phone format is incorrect !!! '),
'Remark' => array ('_ check', '123456', 'comment format is not funny.'), // external function. _ must be added before the function name _
'Remark' => array (new B (), 'test', '000000', 'comment format is not funny '),
), $ _ POST );
If (! $ PostData ['vail _ status']) parent: error ($ postData ['vail _ error']);
}
The above is how to use VailData.
Soon after completion, there may be many places to be improved and bugs to be fixed. I hope you will give more comments,

Note: If you have downloaded the file again, the file is uploaded incorrectly. Sorry.

VailData.zip (4.92 KB download: 214 times)

AD: truly free, domain name + VM + enterprise mailbox = 0 RMB

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.