The validity check in Jquery Easyui

Source: Internet
Author: User

Use the process of an accumulation, for reference.

Easyui How to use the validation box:

//***************************

Missingmessage: Information displayed when not filled in

Validtype: Verification type See example below

Invalidmessage: Information displayed when invalid data type

Required= "true" required

class= "Easyui-validatebox" text validation

Class= "Easyui-numberbox" Digital verification

*****************************//

0. Call data validation method

Return $ ("#form1"). Form (' Validate ');

Example: <asp:button id= "Btn_save" runat= "Server" text= "save" OnClick = "Btn_save_click" onclientclick= "return $ (" #form1 "). Form (' Validate '); "/>

1, verify whether required class= "Easyui-validatebox" missingmessage= "xxx must be filled in"

2. Verify the string length class= "Easyui-validatebox" missingmessage= "xxx must be filled in less than 10 characters"

Validtype= "length[0,2" "invalidmessage=" cannot exceed 2 characters! "

Example:

<input class= "Easyui-validatebox" required= "true" missingmessage= "name must be filled" size= "type=" text "Name=" Arealname " ></input>

3. Verify that the number must be between 5.5-20

precision= "2" means 2 is decimal

class= "Easyui-numberbox" min= "5.5" max= "2" precision= "true" required= "must fill in the numbers between missingmessage="

4, verification must be date yyyy-mm-dd (can only select not editable)

<script> $.fn.datebox.defaults.formatter = function (date) {

var y = date.getfullyear ();

var m = date.getmonth () + 1;

var d = date.getdate ();

Return y + '-' + (M < 10?) ' 0 ' + m:m + '-' + (D < 10?) ' 0 ' + d:d);

};

$.fn.datebox.defaults.parser = function (s) {

if (s) {

var a = S.split ('-');

var d = new Date (parseint (a[0]), parseint (A[1])-1, parseint (a[2]));

return D;

} else {

return new Date ();

}         };

</script>

class= "Easyui-datebox" required= "true" missingmessage= "date must be filled" editable= "false"//if you need to fill in other format types, please modify the formatter function yourself

5. Verification must be mail class= "Easyui-validatebox" missingmessage= "mail must be filled in"

Validtype= "Email" invalidmessage= "please fill in the correct email format"

6, the page time period judgment

The time for name S1 must be greater than the time of name S2 S3 must be greater than S2

<script> $.extend ($.fn.validatebox.defaults.rules,{

timecheck:{

Validator:function (Value,param) {

var s = $ ("input[name=" +param[0]+ "]"). Val (); Because dates are in uniform format, you can directly compare strings otherwise you need Date.parse (_date) conversions

Return value>=s;

},

Message: ' Illegal data '

}

});

</script>

<input name= "S1" class= "Easyui-datebox" required= "true" missingmessage= "date must be filled" editable= "false" ></input >

<input name= "S2" class= "Easyui-datebox" required= "true" validtype= "timecheck[' s1 ']" invalidmessage= "S1 must be greater than S2" Editable= "false" ></input>

<input name= "S3" class= "Easyui-datebox" required= "true" validtype= "timecheck[' S2 ']" editable= "false" ></ Input>

7. Ask the dialog box to submit:

function confirmbtn (msg, control) {

$.messager.confirm (' Ack ', MSG, function (r) {

if (r) {

__doPostBack ("Ctl00$contentph_main$button1", "" ");

Alert (' AA ');

} });

return false; }

onclientclick= "Return confirmbtn (' Confirm? ', this);

--------------------------------------------------------------------------------------------------------------- -



itself written by Validator.js


Extended validation of Easyui forms ¥.extend (¥.fn.validatebox.defaults.rules, {//Verify man CHS: {validator:function (value) {        return/^[\u0391-\uffe5]+¥/.test (value);            }, Message: "" can only input Chinese characters ""},//Mobile phone number verification Mobile: {//value value is the value in the text box Validator:function (value) { var reg =/^1[3|4|5|8|            9]\d{9}¥/;        return reg.test (value);    }, message: "The input phone number pattern is incorrect."            },//domestic zip verification ZipCode: {validator:function (value) {var reg =/^[1-9]\d{5}¥/;        return reg.test (value);    }, message: "The ZIP code must have a 6-digit number beginning at 0." },//user account verification (can only contain _ number letters) accounts: {//param value is [] median value validator:function (value, param) {if (value . length < param[0] | | Value.length > Param[1]) {¥.fn.validatebox.defaults.rules.account.message = "" User name length must be in "" + param[0] + "                "To" "+ param[1" + "Limited" ";            return false;          } else {if (!/^[\w]+¥/.test (value)) {          ¥.fn.validatebox.defaults.rules.account.message = "" The user name can only be made up of numbers, letters, underscores. "";                return false;                } else {return true; }}}, message: "" "}})



Checkname.aspx


<%@ page language= "C #"%><script runat= "server" >    void Page_Load (object sender, System.EventArgs e)    {        if (!string. IsNullOrEmpty (request["name"])        {            String name = "";            Name = request["Name"];            if (name = = "Zhxhdean")            {//When the value in the text box is Zhxhdean, the user is prompted to already exist. This step can go to the database query                Response.Write ("false");                return;            }            else            {                Response.Write ("true");                return;}}}    </script>

The validity check in Jquery Easyui

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.