js認証身分証とメールアドレス

5344 ワード

javascript身分証番号検証正則
//      15  18     ,             。     
//     ,              ,   6              。   
  
function isIdCardNo(num){  
    num = num.toUpperCase();  
    //      15   18 ,15      ,18  17    ,        ,        X。     
    if (!(/(^\d{15}$)|(^\d{17}([0-9]|X)$)/.test(num))) {  
        alert('           ,         !
15 ,18 X。'); return false; } // ISO 7064:1983.MOD 11-2 ,X 10。 // var len, re; len = num.length; if (len == 15) { re = new RegExp(/^(\d{6})(\d{2})(\d{2})(\d{2})(\d{3})$/); var arrSplit = num.match(re); // var dtmBirth = new Date('19' + arrSplit[2] + '/' + arrSplit[3] + '/' + arrSplit[4]); var bGoodDay; bGoodDay = (dtmBirth.getYear() == Number(arrSplit[2])) && ((dtmBirth.getMonth() + 1) == Number(arrSplit[3])) && (dtmBirth.getDate() == Number(arrSplit[4])); if (!bGoodDay) { alert(' !'); return false; } else { // 15 18 // ISO 7064:1983.MOD 11-2 ,X 10。 var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'); var nTemp = 0, i; num = num.substr(0, 6) + '19' + num.substr(6, num.length - 6); for (i = 0; i < 17; i++) { nTemp += num.substr(i, 1) * arrInt[i]; } num += arrCh[nTemp % 11]; return num; } } if (len == 18) { re = new RegExp(/^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/); var arrSplit = num.match(re); // var dtmBirth = new Date(arrSplit[2] + "/" + arrSplit[3] + "/" + arrSplit[4]); var bGoodDay; bGoodDay = (dtmBirth.getFullYear() == Number(arrSplit[2])) && ((dtmBirth.getMonth() + 1) == Number(arrSplit[3])) && (dtmBirth.getDate() == Number(arrSplit[4])); if (!bGoodDay) { alert(dtmBirth.getYear()); alert(arrSplit[2]); alert(' !'); return false; } else { // 18 。 // ISO 7064:1983.MOD 11-2 ,X 10。 var valnum; var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'); var nTemp = 0, i; for (i = 0; i < 17; i++) { nTemp += num.substr(i, 1) * arrInt[i]; } valnum = arrCh[nTemp % 11]; if (valnum != num.substr(17, 1)) { alert('18 ! :' + valnum); return false; } return num; } } return false; }
検証メールボックス
Jsコード 

   :  
function verifyAddress(obj)    
  
{    
  var email = obj;    
  var pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;    
  flag = pattern.test(email);    
  if(flag)    
  {    
    alert(“Your email address is correct!”);    
    return true;    
  }    
  else    
  {    
    alert(“Please try again!”);    
    return false;    
  }    
}     
  
  :[email protected]     
  
  
--------------------------------------------------------------------------------  
  
   :  
function isEmail(str){  
     var email = str;  
     var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;  
     return reg.test(email);  
}  
  :[email protected]    
  
--------------------------------------------------------------------------------  
  
   :  
function isEmail(str){  
     var email = str;  
     var reg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;  
     return reg.test(email);  
}  
  
--------------------------------------------------------------------------------  
  
   :  
function isEmail(str){  
     var email = str;  
     var reg = /^[_a-zA-Z0-9-]+(\\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*\\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(info|name))$/;  
     return reg.test(email);  
}