<script type="text/javascript"> //验证是否是数字 //0 1 2 /^\d*$/ //验证日期 2002-01-03 ///^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})/ //只能是整数 其他输不进去 //<input onKeyUp="this.value=this.value.replace(/[^\d]/g,'')"> //只能是数字 //<input onkeyup="this.value=this.value.replace(/[^\d]/g,'')" onafterpaste="this.value=this.value.replace(/[^\d]/g,'')"> //判断长度(长度不限为0) String.prototype.IsLen = function () { var isRightFormat = false; var minnum = arguments[0] ? arguments[0] : 0; var maxnum = arguments[1] ? arguments[1] : 0; isRightFormat = (minnum == 0 && maxnum == 0 ? true : (calculate_byte(this) >= minnum && calculate_byte(this) <= maxnum ? true : false)); return isRightFormat; } //验证用户名 String.prototype.IsUsername = function () { var myReg = /^[0-9a-zA-Z\-]+$/; if (myReg.test(this)) return true; return false; } //验证密码 String.prototype.IsPassword = function () { var myReg = /^[0-9a-zA-Z]+$/; if (myReg.test(this)) return true; return false; } //验证是否为字母 String.prototype.IsEn = function () { var myReg = /^[a-zA-Z]+$/; if (myReg.test(this)) return true; return false; } //验证是否为汉字 String.prototype.IsCn = function () { var myReg = /^[\u0391-\uFFE5]+$/; if (myReg.test(this)) return true; return false; } //验证E-mail String.prototype.IsEmail = function () { var myReg = /([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)/; if (myReg.test(this)) return true; return false; } //验证MSN String.prototype.IsMSN = function () { var myReg = /([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)/; if (myReg.test(this)) return true; return false; } //验证QQ号码 String.prototype.IsQQ = function () { var myReg = /^[1-9]\d{4,9}$/; if (myReg.test(this)) return true; return false; } //验证域名 String.prototype.IsDoMainName = function () { var myReg = /^[0-9a-zA-Z]([0-9a-zA-Z\-]+\.){1,3}[a-zA-Z]{2,4}?$/; if (myReg.test(this)) return true; return false; } //验证IPV4地址 String.prototype.IsIpv4 = function () { var myReg = /^(2[0-5]{2}|1?[0-9]{1,2}).(2[0-5]{2}|1?[0-9]{1,2}).(2[0-5]{2}|1?[0-9]{1,2}).(2[0-5]{2}|1?[0-9]{1,2})$/; if (myReg.test(this)) return true; return false; } //验证图片地址(不支持由CGI动态生成的图片) String.prototype.IsImgURL = function () { var myReg = /^\.(jpeg|jpg|gif|bmp|png|pcx|tiff|tga|lwf)$/; if (myReg.test(this)) return true; return false; } //验证手机号码 String.prototype.IsCellPhone = function () { var myReg = /^((\(\d{3}\))|(\d{3}\-))?1[3,5]\d{9}$/; if (myReg.test(this)) return true; return false; } //验证固定电话 String.prototype.IsPhone = function () { var myReg = /^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/; if (myReg.test(this)) return true; return false; } //验证邮编 String.prototype.IsZipCode = function () { var myReg = /[0-9]{6}/; if (myReg.test(this)) return true; return false; } //验证身份证号码 String.prototype.IsIdCard = function () { var myReg = /(^([\d]{15}|[\d]{18}|[\d]{17}[xX]{1})$)/; if (myReg.test(this)) return true; return false; } //验证日期格式YY-MM-DD String.prototype.IsDateFormat = function () { var myReg = /^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}$/; if (myReg.test(this)) return true; return false; } //验证时间格式HH:MM:SS String.prototype.IsRangeTime = function () { var myReg = /^(\d{2}):(\d{2}):(\d{2})$/; if (myReg.test(this)) return true; return false; } //验证金额格式 String.prototype.IsMoney = function () { var myReg = /^[0-9]{1,8}[.]{0,1}[0-9]{0,2}$/; if (myReg.test(this)) return true; return false; } //字验证数字格式并判断数字的围(min:最小值;max:最大值.) String.prototype.IsInt = function () { var isRightFormat = false; var minnum = arguments[0] ? arguments[0] : 0; var maxnum = arguments[1] ? arguments[1] : 0; var myReg = /^[-\+]?\d+$/; if (myReg.test(this)) { isRightFormat = (minnum == 0 && maxnum == 0 ? true : (this > minnum && this < maxnum ? true : false)); } return isRightFormat; } //验证搜索关键字 String.prototype.IsSearch = function () { var myReg = /^[\|\"\'<>,.*&@#$;:!^()]/; if (myReg.test(this)) return false; return true; } //js准确计算字符串长度 function calculate_byte(sTargetStr) { var sTmpStr, sTmpChar; var nOriginLen = 0; var nStrLength = 0; sTmpStr = new String(sTargetStr); nOriginLen = sTmpStr.length; for (var i = 0; i < nOriginLen; i++) { sTmpChar = sTmpStr.charAt(i); if (escape(sTmpChar).length > 4) { nStrLength += 2; } else if (sTmpChar != '\r') { nStrLength++; } } return nStrLength; } //验证网址 String.prototype.IsHttpUrl = function () { var myReg = /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/; if (myReg.test(this)) return true; return false; }