2021-10-25 10:40:33
1.不可包含特殊字符的正则表达式
/^((?!\\|\/|:|\*|\?|<|>|\||'|%|\@|\#|\$|\%|\^|\&|\(|\)|\[|\]|\{|\}|\.|\!|\¥|\+|\=|"|”|“).){1,50}$/
注: /^表示开头,$/表示结尾,中间的\表示转义,|表示或(起连接作用),(1,50)表示长度范围为1~50
2.字符串不可包含空格(开头结尾不得为空格)
/^\S*$/ //不可包含任何空格
/^\S([\s\S]*\S)?$/ //头尾不可包含空格
3.IP地址校验
/^([1-9]|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])$/
4.MAC地址校验
/^([A-Fa-f0-9]{2}:){5}[A-Fa-f0-9]{2}$/)
5.子网掩码校验
/^((254|252|248|240|224|192|128)\.0\.0\.0|255\.(254|252|248|240|224|192|128|0)\.0\.0|255\.255\.(254|252|248|240|224|192|128|0)\.0|255\.255\.255\.(254|252|248|240|224|192|128|0))$/
6.默认网关、DNS校验
/^([1-9]|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])$/
7.可输入单条IP或CIDR
/^([0-9]|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])(\.([0-9]|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])){3}(\/([1-9]|[1-2]\d|[3][0-2])){0,1}$/
8.可输入多条IP或CIDR,以分号分隔
/^(?:(?:^|;)(?:[0-9]|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])(\.([0-9]|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])){3}(\/([1-9]|[1-2]\d|[3][0-2])){0,1})+$/
9.可输入多条CIDR,以分号分隔
/^(?:(?:^|;)(?:[0-9]|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])(?:\.(?:[0-9]|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])){3}(?:\/([1-9]|[1-2]\d|[3][0-2])))+$/
10、强密码校验
/((^(?=.*[a-z])(?=.*[A-Z])(?=.*\W)[\da-zA-Z\W]{8,18}$)|(^(?=.*\d)(?=.*[A-Z])(?=.*\W)[\da-zA-Z\W]{8,18}$)|(^(?=.*\d)(?=.*[a-z])(?=.*\W)[\da-zA-Z\W]{8,18}$)|(^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[\da-zA-Z\W]{8,18}$))/ //必须包含大写字母,小写字母,数字和特殊符号中的任意3种,8-18字符
11、时间段校验
//1.时间段校验 例11:12~13:11,不可跨天
/^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]~(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/).test(value)
//2.多个时间段,以逗号分隔,不可跨天
/^((0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]~(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9],){0,4}(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]~(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/).test(value)