跳到主要内容

判断字符串以字母开头,后面字母数字下划线,长度 6-30

const reg1 = new RegExp('^[a-zA-Z]\\w{5,29}$');
const reg2 = /^[a-zA-Z]\w{5,29}$/;
const str = 'A123456';
console.log(reg1.test(str))
console.log(reg2.test(str))

一些简单的

// 邮政编码 6位数字
/\d{6}/
// 小写英文字母
/^[a-z]+$/
// 英文字母
/^[a-zA-z]+$/
// 日期格式 2020-11-04
/^\d{4}-\d{1,2}-\d{1,2}$/
// 用户名,字母开头
/^[a-zA-z]\w{5,17}$/
// 简单的 ip 地址匹配
/\d+.\d+.\d+.\d+/