正则表达式(regular expression)描述了一种字符串匹配的模式,可以用来检查一个串是否含有某种子串、将匹配的子串做替换或者从某个串中取出符合某个条件的子串等。
var validateRegExp = {decmal: "^([+-]?)//d*//.//d+$",// 浮点数decmal1: "^[1-9]//d*.//d*|0.//d*[1-9]//d*$",// 正浮点数decmal2: "^-([1-9]//d*.//d*|0.//d*[1-9]//d*)$",// 负浮点数decmal3: "^-?([1-9]//d*.//d*|0.//d*[1-9]//d*|0?.0+|0)$",// 浮点数decmal4: "^[1-9]//d*.//d*|0.//d*[1-9]//d*|0?.0+|0$",// 非负浮点数(正浮点数 + 0)decmal5: "^(-([1-9]//d*.//d*|0.//d*[1-9]//d*))|0?.0+|0$",// 非正浮点数(负浮点数 +// 0)intege: "^-?[1-9]//d*$",// 整数intege1: "^[1-9]//d*$",// 正整数intege2: "^-[1-9]//d*$",// 负整数num: "^([+-]?)//d*//.?//d+$",// 数字num1: "^[1-9]//d*|0$",// 正数(正整数 + 0)num2: "^-[1-9]//d*|0$",// 负数(负整数 + 0)ascii: "^[//x00-//xFF]+$",// 仅ACSII字符chinese: "^[//u4e00-//u9fa5]+$",// 仅中文color: "^[a-fA-F0-9]{6}$",// 颜色date: "^//d{4}(//-|///|/.)//d{1,2}//1//d{1,2}$",// 日期email: "^//w+((-//w+)|(//.//w+))*//@[A-Za-z0-9]+((//.|-)[A-Za-z0-9]+)*//.[A-Za-z0-9]+$",// 邮件idcard: "^[1-9]([0-9]{14}|[0-9]{17})$",// 身份证ip4: "^(25[0-5]|2[0-4]//d|[0-1]//d{2}|[1-9]?//d)//.(25[0-5]|2[0-4]//d|[0-1]//d{2}|[1-9]?//d)//.(25[0-5]|2[0-4]//d|[0-1]//d{2}|[1-9]?//d)//.(25[0-5]|2[0-4]//d|[0-1]//d{2}|[1-9]?//d)$",// ip地址letter: "^[A-Za-z]+$",// 字母letter_l: "^[a-z]+$",// 小写字母letter_u: "^[A-Z]+$",// 大写字母mobile: "^0?(13|15|18|14|17)[0-9]{9}$",// 手机notempty: "^//S+$",// 非空password: "^.*[A-Za-z0-9//w_-]+.*$",// 密码fullNumber: "^[0-9]+$",// 数字picture: "(.*)//.(jpg|bmp|gif|ico|pcx|jpeg|tif|png|raw|tga)$",// 图片qq: "^[1-9]*[1-9][0-9]*$",// QQ号码rar: "(.*)//.(rar|zip|7zip|tgz)$",// 压缩文件tel: "^[0-9/-()()]{7,18}$",// 电话号码的函数(包括验证国内区号,国际区号,分机号)url: "^http[s]?://////([//w-]+//.)+[//w-]+([//w-./?%&=]*)?$",// urlusername: "^[A-Za-z0-9_//-//u4e00-//u9fa5]+$",// 户名deptname: "^[A-Za-z0-9_()()//-//u4e00-//u9fa5]+$",// 单位名zipcode: "^//d{6}$",// 邮编realname: "^[A-Za-z//u4e00-//u9fa5]+$",// 真实姓名companyname: "^[A-Za-z0-9_()()//-//u4e00-//u9fa5]+$",companyaddr: "^[A-Za-z0-9_()()//#//-//u4e00-//u9fa5]+$",companysite: "^http[s]?://////([//w-]+//.)+[//w-]+([//w-./?%&#=]*)?$"};// 验证规则var validateRules = {isNull: function(str) {return (str == "" || typeof str != "string");},betweenLength: function(str, _min, _max) {return (str.length >= _min && str.length <= _max);},isUid: function(str) {return new RegExp(validateRegExp.username).test(str);},fullNumberName: function(str) {return new RegExp(validateRegExp.fullNumber).test(str);},isPwd: function(str) {return /^.*([/W_a-zA-z0-9-])+.*$/i.test(str);},isPwdRepeat: function(str1, str2) {return (str1 == str2);},isEmail: function(str) {return new RegExp(validateRegExp.email).test(str);},isTel: function(str) {return new RegExp(validateRegExp.tel).test(str);},isMobile: function(str) {return new RegExp(validateRegExp.mobile).test(str);},checkType: function(element) {return (element.attr("type") == "checkbox" || element.attr("type") == "radio" || element.attr("rel") == "select");},isRealName: function(str) {return new RegExp(validateRegExp.realname).test(str);},isCompanyname: function(str) {return new RegExp(validateRegExp.companyname).test(str);},isCompanyaddr: function(str) {return new RegExp(validateRegExp.companyaddr).test(str);},isCompanysite: function(str) {return new RegExp(validateRegExp.companysite).test(str);},simplePwd: function(str) {// var pin = $("#regName").val();// if (pin.length > 0) {// pin = strTrim(pin);// if (pin == str) {// return true;// }// }return pwdLevel(str) == 1;},weakPwd: function(str) {for (var i = 0; i < weakPwdArray.length; i++) {if (weakPwdArray[i] == str) {return true;}}return false;}};//休眠function sleep(numberMillis) {var now = new Date();var exitTime = now.getTime() + numberMillis;while (true) {now = new Date();if (now.getTime() > exitTime) return;}}
以上所述是小编给大家介绍的JavaScript中一些常用的正则表达式(推荐),希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对VEVB武林网网站的支持!
新闻热点
疑难解答