JS Identification method Support 15-bit and 18-bit _javascript skills

Source: Internet
Author: User
Copy Code code as follows:

The HTML page should have an input input box with ID Identity_card, a ipmessage ID error or the correct prompt message where
<script>
ID Card Verification
$ (document). Ready (function () {
$ ("#identity_card"). Change (function () {
var idcard =$ (This). Val ();
Checkdate (Idcard);
});
});
Id
function Checkdate (idcard) {
var socialno = Idcard;
if (Socialno = "")
{
$ (' #ipmessage '). HTML (' input ID number format incorrect, must be 15 to 18-bit ID number ');
Alert ("Enter ID number cannot be empty!");
return (false);
}
if (socialno.length!= && socialno.length!= 18)
{
$ (' #ipmessage '). HTML (' input ID number format incorrect, must be 15 to 18-bit ID number ');
Alert ("Input ID number is not in the correct format!");
return (false);
}
var area={11: "Beijing", 12: "Tianjin", 13: "Hebei", 14: "Shanxi", 15: "Inner Mongolia", 21: "Liaoning", 22: "Jilin", 23: "Heilongjiang", 31: "Shanghai", 32: "Jiangsu", 33: "Zhejiang", 34: "Anhui", 35: "Fujian", 36: "Jiangxi", 37: "Shandong", 41: "Henan", 42: "Hubei", 43: "Hunan", 44: "Guangdong", 45: "Guangxi", 46: "Hainan", 50: "Chongqing", 51: "Sichuan", 52: "Guizhou", 53: "Yunnan", 54: "Tibet", 61: "Shaanxi", 62: "Gansu", 63: "Qinghai", 64: "Ningxia", 65: "Xinjiang", 71: "Taiwan", 81: "Hong Kong", 82: "Macao", 91: "Foreign"};
if (Area[parseint (Socialno.substr (0,2))]==null) {
$ (' #ipmessage '). HTML (' input ID number format incorrect, must be 15 to 18-bit ID number ');
Alert ("Incorrect identity card number (illegal area)!");
return (false);
}
if (socialno.length = 15)
{
Pattern=/^\d{15}$/;
if (Pattern.exec (Socialno) ==null) {
$ (' #ipmessage '). HTML (' input ID number format incorrect, must be 15 to 18-bit ID number ');
Alert ("15-digit ID number must be number!") ");
return (false);
}
var birth = parseint ("n" + socialno.substr (6,2));
var month = Socialno.substr (8,2);
var day = parseint (Socialno.substr (10,2));
Switch (month) {
Case ' 01 ':
Case ' 03 ':
Case ' 05 ':
Case ' 07 ':
Case ' 08 ':
Case ' 10 ':
Case ' 12 ':
if (day>31) {
$ (' #ipmessage '). HTML (' input ID number format incorrect, must be 15 to 18-bit ID number ');
Alert (' Input ID number not formatted correctly! ');
return false;
}
Break
Case ' 04 ':
Case ' 06 ':
Case ' 09 ':
Case ' 11 ':
if (day>30) {
$ (' #ipmessage '). HTML (' input ID number format incorrect, must be 15 to 18-bit ID number ');
Alert (' Input ID number not formatted correctly! ');
return false;
}
Break
Case ' 02 ':
if (birth% 4 = 0 && Birth%!= 0) | | Birth% 400 = 0) {
if (day>29) {
$ (' #ipmessage '). HTML (' input ID number format incorrect, must be 15 to 18-bit ID number ');
Alert (' Input ID number not formatted correctly! ');
return false;
}
} else {
if (day>28) {
$ (' #ipmessage '). HTML (' input ID number format incorrect, must be 15 to 18-bit ID number ');
Alert (' Input ID number not formatted correctly! ');
return false;
}
}
Break
Default
$ (' #ipmessage '). HTML (' input ID number format incorrect, must be 15 to 18-bit ID number ');
Alert (' Input ID number not formatted correctly! ');
return false;
}
var nowyear = new Date (). getyear ();
if (Nowyear-parseint (birth) <15 | | nowyear-parseint (BIRTH) >100) {
$ (' #ipmessage '). HTML (' input ID number format incorrect, must be 15 to 18-bit ID number ');
Alert (' Input ID number not formatted correctly! ');
return false;
}
$ (' #ipmessage '). HTML (' Pass! ');
return (true);
}
var Wi = new Array (
7,9,10,5,8,4,2,1,6,
3,7,9,10,5,8,4,2,1
);
var lsum = 0;
var nnum = 0;
var nchecksum = 0;
for (i = 0; i < ++i)
{
if (Socialno.charat (i) < ' 0 ' | | socialno.charat (i) > ' 9 ')
{
$ (' #ipmessage '). HTML (' input ID number format incorrect, must be 15 to 18-bit ID number ');
Alert ("Input ID number is not in the correct format!");
return (false);
}
Else
{
Nnum = Socialno.charat (i)-' 0 ';
}
Lsum + + nnum * Wi[i];
}
if (socialno.charat) = = ' X ' | | Socialno.charat (+) = ' x ')
{
Lsum + = 10*wi[17];
}
else if (Socialno.charat < ' 0 ' | | socialno.charat () > ' 9 ')
{
$ (' #ipmessage '). HTML (' input ID number format incorrect, must be 15 to 18-bit ID number ');
Alert ("Input ID number is not in the correct format!");
return (false);
}
Else
{
Lsum + + (socialno.charat)-' 0 ') * wi[17];
}
if ((lsum% 11) = = 1)
{
$ (' #ipmessage '). HTML (' Pass! ');
return true;
}
Else
{
$ (' #ipmessage '). HTML (' input ID number format incorrect, must be 15 to 18-bit ID number ');
Alert ("Input ID number is not in the correct format!");
return (false);
}
}
</script>

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.