javascript: 常用正则表达式

时间:2021-02-11 19:45:17
域名验证:^([a-zA-Z0-9]([a-zA-Z0-9/-]{0,61}[a-zA-Z0-9])?/.)+[a-zA-Z]{2,6}$ Email:^[/w.-]+@([0-9a-zA-Z/w-]+/.)+[0-9a-zA-Z]{2,8}$ 验证数字 字母 下划线:^[a-zA-Z_0-9]{1,}$ 验证身份证: function isIdCardNo(num) { var len = num.length; var re; if(len == 15) re = new RegExp(/^(/d{6})()?(/d{2})(/d{2})(/d{2})(/d{3})$/); else if(len == 18) re = new RegExp(/^(/d{6})()?(/d{4})(/d{2})(/d{2})(/d{3})([0-9Xx])$/); else { alert("身份证无效!"); QUERY_FORM.ID_CARD.focus(); return false; } var a = num.match(re); if(a != null) { if (len==15){ var D = new Date("19"+a[3]+"/"+a[4]+"/"+a[5]); var B = D.getYear()==a[3]&&(D.getMonth()+1)==a[4]&&D.getDate()==a[5]; } else{ var D = new Date(a[3]+"/"+a[4]+"/"+a[5]); var B = D.getFullYear()==a[3]&&(D.getMonth()+1)==a[4]&&D.getDate()==a[5]; } if(!B){ alert("输入的身份证号"+a[0]+"里出生日期不对!"); QUERY_FORM.ID_CARD.focus(); return false; } else{ alert('身份证无效!'); return false; } return true; }