jqueryフォーム検証フレームワークが提供する認証方法

1452 ワード

var aCity={11:"  ",12:"  ",13:"  ",14:"  ",15:"   ",
21:"  ",22:"  ",23:"   ",31:"  ",32:"  ",33:"  ",
34:"  ",35:"  ",36:"  ",37:"  ",41:"  ",42:"  ",
43:"  ",44:"  ",45:"  ",46:"  ",50:"  ",51:"  "
,52:"  ",53:"  ",54:"  ",61:"  ",62:"  ",63:"  ",
64:"  ",65:"  ",71:"  ",81:"  ",82:"  ",91:"  "} 


function isCardID(sId){
  var iSum=0 ;
  var info="" ;
  if(!/^\d{17}(\d|x)$/i.test(sId)) return "              ";
  sId=sId.replace(/x$/i,"a");
  if(aCity[parseInt(sId.substr(0,2))]==null) return "         ";
  sBirthday=sId.substr(6,4)+"-"+Number(sId.substr(10,2))+"-"+Number(sId.substr(12,2));
  var d=new Date(sBirthday.replace(/-/g,"/")) ;
  if(sBirthday!=(d.getFullYear()+"-"+ (d.getMonth()+1) + "-" + d.getDate()))return "           ";
  for(var i = 17;i>=0;i --) iSum += (Math.pow(2,i) % 11) * parseInt(sId.charAt(17 - i),11) ;
  if(iSum%11!=1) return "          ";
  return true;//aCity[parseInt(sId.substr(0,2))]+","+sBirthday+","+(sId.substr(16,1)%2?" ":" ")
}