验证地址
需要把表达式首尾斜杠去掉
- IP地址验证:
/^(\d|[1-9]\d|1\d{2}|2[0-5][0-5])\.(\d|[1-9]\d|1\d{2}|2[0-5][0-5])\.(\d|[1-9]\d|1\d{2}|2[0-5][0-5])\.(\d|[1-9]\d|1\d{2}|2[0-5][0-5])$/
格式是由“.”分割的四部分,每部分的范围是 0-255;
每段的正则可以分几部分来写: 200—255;100-199;10-99;0-9;
每一部分对应的正则表达式: 2[0-5][0-5]; 1\d{2}; [1-9]\d; \d
连起来为: \d|[1-9]\d|1\d{2}|2[0-5][0-5]
IP的正则就是 (\d|[1-9]\d|1\d{2}|2[0-5][0-5]).(\d|[1-9]\d|1\d{2}|2[0-5][0-5]).(\d|[1-9]\d|1\d{2}|2[0-5][0-5]).(\d|[1-9]\d|1\d{2}|2[0-5][0-5])
- Mac 地址验证(一):
/^[A-F0-9]{2}(-[A-F0-9]{2}){5}$|^[A-F0-9]{2}(:[A-F0-9]{2}){5}$/
- Mac地址有两种:
58:E8:76:83:A2:C7
/^[A-Fa-f0-9]{1,2}\:[A-Fa-f0-9]{1,2}\:[A-Fa-f0-9]{1,2}\:[A-Fa-f0-9]{1,2}\:[A-Fa-f0-9]{1,2}\:[A-Fa-f0-9]{1,2}$/ 58-E8-76-83-A2-C7 /^[A-Fa-f0-9]{1,2}\-[A-Fa-f0-9]{1,2}\-[A-Fa-f0-9]{1,2}\-[A-Fa-f0-9]{1,2}\-[A-Fa-f0-9]{1,2}\-[A-Fa-f0-9]{1,2}$/
简写后:
/^[A-F0-9]{2}(-[A-F0-9]{2}){5}$/
/^[A-F0-9]{2}(:[A-F0-9]{2}){5}$/
- 端口验证:
/^([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-5]{2}[0-3][0-5])$/
格式是 0-65535 分为几部分来构造: 60000-65535;10000-59999;1000-9999;100-999;10-99;0-9; 每部分的正则是: 6[0-5]{2}[0-3][0-5]; [1-5]\d{4}; [1-9]\d{3}; [1-9]\d{2};[1-9]\d; [0-9] 整理完就是: ([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-5]{2}[0-3][0-5])
- 经度校验:
/^[\-\+]?(0?\d{1,2}|0?\d{1,2}\.\d{1,15}|1[0-7]?\d{1}|1[0-7]?\d{1}\.\d{1,15}|180|180\.0{1,15})$/
- 纬度校验:
/^[\-\+]?([0-8]?\d{1}|[0-8]?\d{1}\.\d{1,15}|90|90\.0{1,15})$/
- 车牌号码校验:
/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领]{1}[a-hj-zA-HJ-Z]{1}[警京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼]{0,1}[a-hj-np-zA-HJ-NP-Z0-9]{4,5}[a-hj-np-zA-HJ-NP-Z0-9挂学警港澳]{1}$/