正则例子
常用正则:https://www.kuangyx.cn/docs/文章/前端/常用正则.html
1.只包含小写字母、数字及分隔符('-'),且必须以小写字母开头, 字母或数字结尾
const reg = /[1](([a-z0-9-])[a-z0-9])?$/;
2.只包含小写字母、数字及分隔符('-'),不允许相邻分隔符('-'),且必须以小写字母开头, 字母或数字结尾
const reg = /[2](((?!--)[a-z0-9-])[a-z0-9])?$/;
3.正确的端口号
const reg = /^([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$/
const reg = /([1-9](\d{0,3}))$|([1-5]\d{4})$|(6[0-4]\d{3})$|(65[0-4]\d{2})$|(655[0-2]\d)$|(6553[0-5])$/
4.正确ip
const reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5]).(\d{1,2}|1\d\d|2[0-4]\d|25[0-5]).(\d{1,2}|1\d\d|2[0-4]\d|25[0-5]).(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
5.正确手机号
const reg = /^(13[0-9]|14[01,4-9]|15[0-3,5-9]|16[5-7]|17[0135678]|18[0-9]|19[189])\d{8}$/