IPV6验证正则表达式

验证ipv6的正则表达式:
例:fe80::ec61:c1d1:9827:82be%13
\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*
 
 
//mac地址验证 例:18-03-73-9B-4A-D5
 ^([A-Fa-f0-9]{2}-){5}[A-Fa-f0-9]{2}$ 横杆连接
^([A-Fa-f0-9]{2}){5}[A-Fa-f0-9]{2}$ 无间隔
^([A-Fa-f0-9]{2}:){5}[A-Fa-f0-9]{2}$ 英文冒号连接
^([A-Fa-f0-9]{2} ){5}[A-Fa-f0-9]{2}$ 空格连接

// 前后台使用的mac地址校验正则(^和$可以严格控制开头和结尾);允许ipV4mac和ipV6mac
例:18-03-73-9B-4A-D5或18-03-73-9B-4A-D5-00-0e
^([A-Fa-f0-9]{2}-){5,7}[A-Fa-f0-9]{2}$|^([A-Fa-f0-9]{2}){5,7}[A-Fa-f0-9]{2}$|^([A-Fa-f0-9]{2}:){5,7}[A-Fa-f0-9]{2}$|^([A-Fa-f0-9]{2} ){5,7}[A-Fa-f0-9]{2}$

 

posted @ 2017-12-25 14:22  $>_<$  阅读(7751)  评论(1编辑  收藏  举报