常用的js正则表达式

2009年4月30日星期四

常用的js正则表达式

1.验证身份证号
目前的身份证号是15位或者18位,其中最后一位可以为X或者数字。

functionisIDCard(strNumber){varnewPar=/^(([0-9]{14}|[0-9]{17})[0-9x])$/;returnnewPar.test(strNumber);}

2.验证email

functionisEmail(strNumber){varnewPar=/^([a-zA-Z0-9])+@([a-zA-Z0-9])+\.([a-zA-Z0-9])+/;returnnewPar.test(strNumber);}

3.验证手机号码

functionisMobilePhoneNumber(strNumber){varnewPar=/^(((13[0-9]{1})|(15[0-9]{1}))+\d{8})$/;returnnewPar.test(strNumber);}

4.验证电话号码

functionisPhone(strNumber){varnewPar=/(^[0-9]{3,4}\-[0-9]{7,8}$)|(^[0-9]{7,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$)/;returnnewPar.test(strNumber);}
5.验证邮政编码

functionisPostCard(strNumber){varnewPar=/^[1-9]{1}[0-9]{5}$/;returnnewPar.test(strNumber);}

6.去掉前后空格等

functiontrim(str){returnstr.replace(/(^\s*)|(\s*$)/g,"");}
使用方法如:

if($("y\\.radialOrgFax").val()!=null$("y\\.radialOrgFax").val()!=""){if(!isPhone($("y\\.radialOrgFax").val())){alert("传真号码不正确!");returnfalse;}}评论发表评论
您还没有登录,请登录后发表评论(快捷键Alt+S/Ctrl+Enter)pipe搜索本博客最近访客博客分类我的留言簿其他分类最近加入圈子存档最新评论评论排行榜声明:JavaEye文章版权属于作者,受法律保护。没有作者书面许可不得转载。若作者同意转载,必须以超链接形式标明文章原始出处和作者。

0 评论:

发表评论