标签:
邮箱格式判断
1 // 是否是 合法邮箱 2 BOOL IsValidEmail(const CString strEmail) 3 { 4 if( strEmail.GetLength() < 5 ) //26个小写字母 5 { 6 return FALSE; 7 } 8 char ch; 9 10 int atCount =0; 11 int atPos = 0; 12 int dotCount = 0; 13 for(int i=0; i<strEmail.GetLength(); i++) // 从0 开始判断 14 { 15 ch = strEmail[i]; 16 if( IsValidChar(ch) ) 17 { 18 if(ch==64) //"@" 19 { 20 atCount ++; 21 atPos = i; 22 } 23 else if( (atCount>0) && (ch==46) )//@ 符号后的"."号 24 { 25 dotCount ++; 26 } 27 } 28 else 29 { 30 return FALSE; 31 } 32 } 33 //6. 结尾不可以是字符 "@" 或者 "". 34 if( ch == 46 ) 35 { 36 return FALSE; 37 } 38 //2. 必须包含一个 并且 只有一个符号“@” 39 //3. @ 后必须包含至少一个至多三个符号"." 40 if( (atCount!=1) || (dotCount<1) || (dotCount>3) ) 41 return FALSE; 42 //5. 不允许储蓄“@.” 或者 ".@" 43 int x=-1, y=-1; 44 x=strEmail.Find(_T("@.")); 45 y=strEmail.Find(_T(".@")); 46 if( x>0 || y>0 ) 47 { 48 return FALSE; 49 } 50 return TRUE; 51 }
身份证:
1 //身份证正则表达式(15位) 2 isIDCard1=/^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$/; 3 //身份证正则表达式(18位) 4 isIDCard2=/^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{4}$/; 5 地区、性别和身份证进行判断的正则表达式: 6 <script> 7 var 8 aCity={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",33:"浙江",34:" 9 10 安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州" 11 12 ,53:"云南",54:"西藏",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"} 13 14 function cidInfo(sId){ 15 var iSum=0 16 var info="" 17 if(!/^\d{17}(\d|x)$/i.test(sId))return false; 18 sId=sId.replace(/x$/i,"a"); 19 if(aCity[parseInt(sId.substr(0,2))]==null)return "Error:非法地区"; 20 sBirthday=sId.substr(6,4)+"-"+Number(sId.substr(10,2))+"-"+Number(sId.substr(12,2)); 21 var d=new Date(sBirthday.replace(/-/g,"/")) 22 if(sBirthday!=(d.getFullYear()+"-"+ (d.getMonth()+1) + "-" + d.getDate()))return "Error:非法生日"; 23 for(var i = 17;i>=0;i --) iSum += (Math.pow(2,i) % 11) * parseInt(sId.charAt(17 - i),11) 24 if(iSum%11!=1)return "Error:非法证号"; 25 return aCity[parseInt(sId.substr(0,2))]+","+sBirthday+","+(sId.substr(16,1)%2?"男":"女") 26 }
标签:
原文地址:http://www.cnblogs.com/aure/p/4276123.html