代码如下:
<script language="javascript"> //校验普通电话、传真号码:可以“+”开头,除数字外,可含有“-” //edit by www.jb200.com function isTel(object) { var s =document.getElementById(object.id).value; //电话和手机号码验证 var pattern =/^((d{11})|^((d{7,8})|(d{4}|d{3})-(d{7,8})|(d{4}|d{3})-(d{7,8})-(d{4}|d{3}|d{2}|d{1})|(d{7,8})-(d{4}|d{3}|d{2}|d{1}))$)/; // var pattern =/^(([0+]d{2,3}-)?(0d{2,3})-)(d{7,8})(-(d{3,}))?$/; //var pattern =/(^[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}$)/; if(s!="") { if(!pattern.exec(s)) { alert('请检查电话号码是否输入有误'); object.value=""; object.focus(); } } else { alert('电话号码不能为空'); } } </script>