Data Verification: validator, DWZ, validatordwz
Data verification is often used in the system. data verification can be written by yourself or generated by now. Now we can record the usage of the two types of libraries,
Validator
<! Doctype html public "-// W3C // dtd html 4.0 // EN" "http://www.w3.org/TR/html4/strict.dtd">
Use data-rule to set the data validation format,
To add a new validation type, you only need to add a regular expression to the zh_CN.js file.
As follows (part of the Code)
Rules: {digits: [/^ \ d + $/, "enter an integer"], doubles: [/^ [0-9] * [.] {0, 1} [0-9] * $/, "enter a number"], positiveinteger: [/^ [1-9] [0-9] * $ /, "Enter a positive integer"], letters: [/^ [a-z] + $/I, "{0} can only enter letters"], tel: [/^ (? :(?: 1 [3-9] \ d {9}) | (?: 0 \ d {2, 3} [-]? [1-9] \ d {6, 7}) | (?: [48] 00 [-]? [1-9] \ d {6}) $/, "incorrect contact number format"], mobile: [/^ 1 [3-9] \ d {9} $/, "Incorrect Mobile Phone Number Format"], email: [/^ (?: [A-z0-9] + [_ \-+.]?) * [A-z0-9] + @(? :( [A-z0-9] + -?) * [A-z0-9] + \.) + ([a-z] {2,}) + $/I, "Incorrect email format"], qq: [/^ [1-9] \ d {4,} $/, "Incorrect QQ number format"], date: [/^ \ d {4}-\ d {1, 2}-\ d {1, 2} $/, "enter the correct date, for example, yyyy-mm-dd"], time: [/^ ([01] \ d | 2 [0-3]) (: [0-5] \ d) {1, 2} $ /, "Enter the correct time, for example, 14: 30 or 14:30:00"], ID_card: [/^ [1-9] \ d {5} [1-9] \ d {3} (0 \ d) | (1 [0-2]) ([0 | 1 | 2] \ d) | 3 [0-1]) (\ d {4 }) | \ d {3} [A-Z] | \ d {3} [a-z]) $/, "enter the correct ID number"], url: [/^ (https? | Ftp): \/[^ \ s] + $/I, "incorrect URL format"], postcode: [/^ [1-9] \ d {5} $/, "Incorrect zip code format"], chinese: [/^ [\ u0391-\ uFFE5] + $/, "enter Chinese"], contentsixty: [/^. [1-60] + $/, "no more than 60 characters"], username: [/^ \ w {3, 12} $ /, "Enter 3-12 digits, letters, and underscores"], password: [/^ [0-9a-zA-Z] {6, 16} $/, "the password consists of 6-16 digits and letters"], accept: function (element, params) {if (! Params) return true; var ext = params [0]; return (ext = '*') | (new RegExp (".(?: "+ (Ext |" png | jpg | jpeg | gif ") +") $ "," I ")). test (element. value) | this. renderMsg ("only accept the {1} suffix", ext. replace ('| ',','));}}});
2. DWZ Data Validation
The html code is as follows:
<Html>
The results are quite good, but I personally prefer the first one, which is convenient and may be used for many reasons.
How does dwz add custom form verification?
Find if ($. validator) {In the dwz js file, and then add
$. Validator. addMethod ("Verification name", function (value, element ){
Return this. optional (element) | regular expression. test (value );
}, "Verification information ");
How to write the AjaxValidator verification page?
Public void ProcessRequest (HttpContext context)
{
If (context. Request. QueryString ["mode"] = "0 ")
{
String id = context. Request. QueryString ["txtUserId"]. ToString ();
User bll_shu = new User ();
If (bll_shu.CheckUserID ("0", id ))
{
Context. Response. Write ("n ");
}
Else
{
Context. Response. Write ("y ");
}
}
Else
{
String id = context. Request. QueryString ["id"]. ToString ();
Bll_shu = new User ();
If (bll_shu.CheckUserID ("1", id ))
{
Context. Response. Write ("n ");
}
Else
{
Context. Response. Write ("y ");
}
}
Context. Response. End ();
}
Public bool IsReusable
{
Get
{
Return false;
}
}