jquery Validate date and ID card verification example

Source: Internet
Author: User

jquery Validate date and ID card verification example

Here's validate's validate.js.

Jquery.extend (JQuery.validator.messages, {
Required: "Must fill",
Remote: "Please fix this field",
Email: "Please enter the correct format email",
URL: "Please enter a valid URL",
Date: "Please enter a valid date",
Dateiso: "Please enter a valid date (ISO).",
Number: "Please enter legal numbers",
Digits: "Only integers can be entered",
CreditCard: "Please enter a valid credit card number",
Equalto: "Please enter the same value again",
Accept: "Please enter a string with a legal suffix name",
Maxlength:jQuery.validator.format ("Please enter a string with a maximum length of {0}"),
Minlength:jQuery.validator.format ("Please enter a string with a length of at least {0}"),
Rangelength:jQuery.validator.format ("Please enter a string between {0} and {1}"),
Range:jQuery.validator.format ("Please enter a value between {0} and {1}"),
Max:jQuery.validator.format ("Please enter a value of max {0}"),
Min:jQuery.validator.format ("Please enter a value of min {0}")
});
$ (document). Ready (function () {
JQuery.validator.addMethod ("Isidcardno", function (value, Element) {
return this.optional (Element) | | Isidcardno (value);
"Please enter your ID number correctly");
});

Increase ID Verification
function Isidcardno (num) {
var Factorarr = new Array (7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1);
var paritybit = new Array ("1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2");
var vararray = new Array ();
var intvalue;
var lngproduct = 0;
var intcheckdigit;
var intstrlen = num.length;
var idNumber = num;
Initialize
if ((Intstrlen!=) && (Intstrlen!= 18)) {
return false;
}
Check and set value
for (i = 0; i < Intstrlen; i++) {
Vararray[i] = Idnumber.charat (i);
if ((Vararray[i] < ' 0 ' | | | vararray[i] > ' 9 ') && (i!= 17)) {
return false;
else if (I < 17) {
Vararray[i] = vararray[i] * Factorarr[i];
}
}

if (Intstrlen = = 18) {
Check Date
var Date8 = idnumber.substring (6, 14);
if (IsDate8 (date8) = = False) {
return false;
}
Calculate the sum of the products
for (i = 0; i < i++) {
Lngproduct = lngproduct + vararray[i];
}
Calculate the check digit
Intcheckdigit = paritybit[lngproduct% 11];
Check last digit
if (vararray[17]!= intcheckdigit) {
return false;
}
}
else {//length is 15
Check Date
var date6 = idnumber.substring (6, 12);
if (IsDate6 (date6) = = False) {
return false;
}
}
return true;
}
function IsDate6 (sdate) {
if (!/^[0-9]{6}$/.test (sdate)) {
return false;
}
Year of Var, month, day;
Year = sdate.substring (0, 4);
month = sdate.substring (4, 6);
if (Year < 1700 | | |/year > 2500) return False
if (Month < 1 | | | month >) return False
return True
}
/**
* To determine whether the "YYYYMMDD" type of period
*
*/
function IsDate8 (sdate) {
if (!/^[0-9]{8}$/.test (sdate)) {
return false;
}
Year of Var, month, day;
Year = sdate.substring (0, 4);
month = sdate.substring (4, 6);
Day = sdate.substring (6, 8);
var iamonthdays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
if (Year < 1700 | | |/year > 2500) return False
If ((year% 4 = 0) && (year% 100!= 0)) | | (Year% 400 = 0)) IAMONTHDAYS[1] = 29;
if (Month < 1 | | | month >) return False
if (Day < 1 | | |/day > IAMONTHDAYS[MONTH-1]) return False
return True
}

Instance

<asp Tutorial: Button id= "Btncreateyearparameter" visible= "false" runat= "Server" text= "onclick=" Btncreateyearparameter _click "
cssclass= "BTN" onclientclick= "$ (' #form1 '). Validate ();"/>

Foreground control:

<asp:dropdownlist cssclass= "Shortselect required" id= "ddlcity" runat= "Server" >
</asp:DropDownList>

jquery JS Code:

function Initvalidate () {
$ ("#MainContent_btnSave, #MainContent_btnAnalysis, #btnSave"). Click (function () {//These buttons all validate, but the buttons we discuss are no longer so $ (' # Form1 '). Validate (); Use this.
$ (' #form1 '). Validate ();
});
}

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.