La copie de code est la suivante:
// La page HTML doit avoir une boîte d'entrée d'entrée avec id identity_card, et un endroit pour inviter un message si la carte d'identité avec id ipMessage est erronée ou correcte ou est invitée.
<cript>
// Vérification de la carte d'identité
$ (document) .ready (function () {
$ ("# identité_card"). Change (function () {
var idcard = $ (this) .val ();
Checkdate (idcard);
});
});
//Carte d'identité
Fonction CheckDate (idcard) {
var socialno = idcard;
if (socialno == "")
{
$ ('# ipMessage'). html ('Le format du numéro d'identification d'entrée est incorrect, il doit être un numéro d'identification de 15 à 18 chiffres');
alert ("Entrer le numéro d'identification ne peut pas être vide!");
return (false);
}
if (socialno.length! = 15 && socialno.length! = 18)
{
$ ('# ipMessage'). html ('Le format du numéro d'identification d'entrée est incorrect, il doit être un numéro d'identification de 15 à 18 chiffres');
alert ("Le format du numéro d'identification d'entrée est incorrect!");
return (false);
}
Var Area = {11: "Beijing", 12: "Tianjin", 13: "Hebei", 14: "Shanxi", 15: "Mongolie intérieure", 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:" étranger "};
if (Area [ParseInt (Socialno.Substr (0,2))] == null) {
$ ('# ipMessage'). html ('Le format du numéro d'identification d'entrée est incorrect, il doit être un numéro d'identification de 15 à 18 chiffres');
alert ("Numéro d'identification incorrect (zone illégale)!");
return (false);
}
if (socialno.length == 15)
{
motif = / ^ / d {15} $ /;
if (pattern.exec (socialno) == null) {
$ ('# ipMessage'). html ('Le format du numéro d'identification d'entrée est incorrect, il doit être un numéro d'identification de 15 à 18 chiffres');
alert ("le numéro d'identification à 15 chiffres doit être un nombre!");
return (false);
}
var naissance = parseInt ("19" + socialno.substr (6,2));
Var Month = Socialno.Substr (8,2);
var day = paSeInt (Socialno.Substr (10,2));
commutateur (mois) {
cas «01»:
cas «03»:
cas «05»:
cas «07»:
cas «08»:
cas «10»:
cas «12»:
if (jour> 31) {
$ ('# ipMessage'). html ('Le format du numéro d'identification d'entrée est incorrect, il doit être un numéro d'identification de 15 à 18 chiffres');
alert («Le numéro d'identification d'entrée n'est pas dans le format correct!»);
retourne false;
}
casser;
cas «04»:
cas «06»:
cas «09»:
cas «11»:
if (jour> 30) {
$ ('# ipMessage'). html ('Le format du numéro d'identification d'entrée est incorrect, il doit être un numéro d'identification de 15 à 18 chiffres');
alert («Le numéro d'identification d'entrée n'est pas dans le format correct!»);
retourne false;
}
casser;
cas «02»:
if ((naissance% 4 == 0 && naissance% 100! = 0) || naissance% 400 == 0) {
if (jour> 29) {
$ ('# ipMessage'). html ('Le format du numéro d'identification d'entrée est incorrect, il doit être un numéro d'identification de 15 à 18 chiffres');
alert («Le numéro d'identification d'entrée n'est pas dans le format correct!»);
retourne false;
}
} autre {
if (jour> 28) {
$ ('# ipMessage'). html ('Le format du numéro d'identification d'entrée est incorrect, il doit être un numéro d'identification de 15 à 18 chiffres');
alert («Le numéro d'identification d'entrée n'est pas dans le format correct!»);
retourne false;
}
}
casser;
défaut:
$ ('# ipMessage'). html ('Le format du numéro d'identification d'entrée est incorrect, il doit être un numéro d'identification de 15 à 18 chiffres');
alert («Le numéro d'identification d'entrée n'est pas dans le format correct!»);
retourne false;
}
var Nowyear = new Date (). Getyear ();
if (nowyear - parseInt (naissance) <15 || Nowyear - ParseInt (naissance)> 100) {
$ ('# ipMessage'). html ('Le format du numéro d'identification d'entrée est incorrect, il doit être un numéro d'identification de 15 à 18 chiffres');
alert («Le numéro d'identification d'entrée n'est pas dans le format correct!»);
retourne false;
}
$ ('# ipMessage'). html ('pass!');
return (true);
}
var wi = nouveau tableau (
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;
pour (i = 0; i <17; ++ i)
{
if (socialno.charat (i) <'0' || socialno.charat (i)> '9')
{
$ ('# ipMessage'). html ('Le format du numéro d'identification d'entrée est incorrect, il doit être un numéro d'identification de 15 à 18 chiffres');
alert ("Le format du numéro d'identification d'entrée est incorrect!");
return (false);
}
autre
{
nnum = socialno.charat (i) - '0';
}
lsum + = nnum * wi [i];
}
if (socialno.charat (17) == 'x' || socialno.charat (17) == 'x')
{
lsum + = 10 * wi [17];
}
else if (Socialno.Charat (17) <'0' || Socialno.Charat (17)> '9')
{
$ ('# ipMessage'). html ('Le format du numéro d'identification d'entrée est incorrect, il doit être un numéro d'identification de 15 à 18 chiffres');
alert ("Le format du numéro d'identification d'entrée est incorrect!");
return (false);
}
autre
{
lsum + = (Socialno.Charat (17) - '0') * Wi [17];
}
if ((lsum% 11) == 1)
{
$ ('# ipMessage'). html ('pass!');
Retour Vrai;
}
autre
{
$ ('# ipMessage'). html ('Le format du numéro d'identification d'entrée est incorrect, il doit être un numéro d'identification de 15 à 18 chiffres');
alert ("Le format du numéro d'identification d'entrée est incorrect!");
return (false);
}
}
</cript>