工作需求常用的正则表达式

1.手机号正则

// 中国大陆手机号正则表达式
var reg = /^1[3|4|5|6|7|8|9][0-9]{9}$/;
// 使用正则表达式判断手机号是否合法
if (reg.test(phoneNumber)) {
    
    
  console.log("手机号合法");
} else {
    
    
  console.log("请输入正确的手机号码");
}

2. QQ号正则

// QQ号正则表达式
var reg = /^[1-9][0-9]{4,10}$/;
// 使用正则表达式判断QQ号是否合法
if (reg.test(qq)) {
    
    
  console.log("QQ号合法");
} else {
    
    
  console.log("5-11位数字,首位不能为0");
}

3.微信号正则

// 微信号正则表达式
var reg = /^[a-zA-Z][-_a-zA-Z0-9]{5,19}$/;
// 使用正则表达式判断微信号是否合法
if (reg.test(wechat)) {
    
    
  console.log("微信号合法");
} else {
    
    
  console.log("6-20个字符,可使用字母、数字、下划线,需以字母开头");
}

4.邮箱正则

// 邮箱正则表达式
var reg = /^([a-zA-Z0-9_\.\-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
// 使用正则表达式判断邮箱是否合法
if (reg.test(email)) {
    
    
  console.log("邮箱合法");
} else {
    
    
  console.log("请输入正确的邮箱地址");
}

5.工作单位正则

// 工作单位正则表达式
var reg = /^[\u4E00-\u9FA5A-Za-z0-9_]+$/;
// 使用正则表达式判断工作单位是否合法
if (reg.test(company)) {
    
    
  console.log("工作单位合法");
} else {
    
    
  console.log("工作单位不合法");
}

6.身份证号正则

// 身份证号正则表达式
var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
// 使用正则表达式判断身份证号是否合法
if (reg.test(idNumber)) {
    
    
  console.log("身份证号合法");
} else {
    
    
  console.log("请输入正确的身份证号码");
}

7.职务正则

// 职务正则表达式
var reg = /^[\u4E00-\u9FA5A-Za-z0-9_]+$/;
// 使用正则表达式判断职务是否合法
if (reg.test(position)) {
    
    
  console.log("职务合法");
} else {
    
    
  console.log("职务不合法");
}

8.邮政编码正则

// 邮政编码正则表达式
var reg = /^[1-9][0-9]{5}$/;
// 使用正则表达式判断邮政编码是否合法
if (reg.test(postcode)) {
    
    
  console.log("邮政编码合法");
} else {
    
    
  console.log("请输入正确的邮政编码");
}

9.通讯地址正则

// 通讯地址正则表达式
var reg = /^[\u4E00-\u9FA5a-zA-Z0-9_]+$/;
// 使用正则表达式判断通讯地址是否合法
if (reg.test(address)) {
    
    
  console.log("通讯地址合法");
} else {
    
    
  console.log("通讯地址不合法");
}

10.传真正则

// 传真正则表达式
var reg = /^(\d{3,4}-)?\d{7,8}$/;
// 使用正则表达式判断传真是否合法
if (reg.test(fax)) {
    
    
  console.log("传真合法");
} else {
    
    
  console.log("传真不合法");
}

11.单位类别正则

// 单位类别正则表达式
var reg = /^[\u4E00-\u9FA5]+$/;
// 使用正则表达式判断单位类别是否合法
if (reg.test(category)) {
    
    
  console.log("单位类别合法");
} else {
    
    
  console.log("单位类别不合法");
}

12.判断是否是数字的正则

// 数字正则表达式
var reg = /^[0-9]+$/;
// 使用正则表达式判断字符串是否是数字
if (reg.test(str)) {
    
    
  console.log("字符串是数字");
} else {
    
    
  console.log("字符串不是数字");
}

13.办公室电话正则

// 办公室电话正则表达式
var reg = /^(\d{3,4}-)?\d{7,8}$/;
// 使用正则表达式判断办公室电话是否合法
if (reg.test(telephone)) {
    
    
  console.log("办公室电话合法");
} else {
    
    
  console.log("办公室电话不合法");
}

14.密码不能少于8位正则

//密码不能少于8位的正则表达式
var reg=/^(?=.*\S).{8,}$/;
// 使用正则表达式判断密码是否合法
if (reg.test(password)) {
    
    
  console.log("密码合法");
} else {
    
    
  console.log("密码不合法");
}

猜你喜欢

转载自blog.csdn.net/weixin_61529967/article/details/132291808