![](/style/images/good.png)
2
![](/style/images/bad.png)
求助正则大佬
source link: https://www.v2ex.com/t/855137
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
由于用了 xrender ,表单字段校验全部得用一个正则来配置完成,遇到了一些困难,求助各位大佬,需求如下(主要是第一个):
![49fb7a1f746fd7e49102a91072aa57b](https://user-images.githubusercontent.com/9512362/170164316-179f69d8-bc72-42e5-b891-40e0da4015e0.png)
第 1 条附言 · 20 小时 29 分钟前
2. 端口检查的:
^([1-9]|[1-9]\\d{1,3}|[1-6][0-5][0-5][0-3][0-5])$|^([1-9]|[1-9]\\d{1,3}|[1-6][0-5][0-5][0-3][0-5])-([1-9]|[1-9]\\d{1,3}|[1-6][0-5][0-5][0-3][0-5])$
有没有更好的方案,欢迎大佬指教
^([1-9]|[1-9]\\d{1,3}|[1-6][0-5][0-5][0-3][0-5])$|^([1-9]|[1-9]\\d{1,3}|[1-6][0-5][0-5][0-3][0-5])-([1-9]|[1-9]\\d{1,3}|[1-6][0-5][0-5][0-3][0-5])$
有没有更好的方案,欢迎大佬指教
第 2 条附言 · 20 小时 10 分钟前
端口号校验更正:
^([0-9]|[1-9]\d|[1-9]\d{2}|[1-9]\d{3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$|^([0-9]|[1-9]\d|[1-9]\d{2}|[1-9]\d{3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])-([0-9]|[1-9]\d|[1-9]\d{2}|[1-9]\d{3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$
^([0-9]|[1-9]\d|[1-9]\d{2}|[1-9]\d{3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$|^([0-9]|[1-9]\d|[1-9]\d{2}|[1-9]\d{3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])-([0-9]|[1-9]\d|[1-9]\d{2}|[1-9]\d{3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$
第 3 条附言 · 19 小时 31 分钟前
ip 、ip 范围、网段及域名校验:
(^((?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(?:(\/([1-9]|[1-2]\d|3[0-1]))|(\-((?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))))?)|((?:(?:[a-zZ-Z0-9]+)\.){2}((com|org|net)\.)?(com|cn|net|org|biz|info|cc|tv|top|vip)))
(^((?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(?:(\/([1-9]|[1-2]\d|3[0-1]))|(\-((?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))))?)|((?:(?:[a-zZ-Z0-9]+)\.){2}((com|org|net)\.)?(com|cn|net|org|biz|info|cc|tv|top|vip)))
第 4 条附言 · 18 小时 29 分钟前
ip 、ip 范围、网段及域名校验正则:
^(?:(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(?:-(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])|(?:[0-9]|[1-2][0-9]|3[0-2]))?|(?:[a-z0-9]+(?:-[a-z0-9]+)*\.)+[a-z]{2,})|((?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(?:(\/([1-9]|[1-2]\d|3[0-1])))?)$
端口及端口范围校验正则:
^([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])(?:-([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]))?$
非常感谢评论区各位大佬提供的各种思路和帮助,希望对有相同需求的朋友也有帮助。
^(?:(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(?:-(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])|(?:[0-9]|[1-2][0-9]|3[0-2]))?|(?:[a-z0-9]+(?:-[a-z0-9]+)*\.)+[a-z]{2,})|((?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(?:(\/([1-9]|[1-2]\d|3[0-1])))?)$
端口及端口范围校验正则:
^([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])(?:-([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]))?$
非常感谢评论区各位大佬提供的各种思路和帮助,希望对有相同需求的朋友也有帮助。
第 5 条附言 · 16 小时 22 分钟前
ip 、ip 范围、网段及域名校验正则:
^(?:(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(?:-(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])|\/(?:[0-9]|[1-2][0-9]|3[0-2]))?|(?:[a-z0-9]+(?:-[a-z0-9]+)*\.)+[a-z]{2,})$
端口及端口范围校验正则:
^([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])(?:-([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]))?$
^(?:(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(?:-(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])|\/(?:[0-9]|[1-2][0-9]|3[0-2]))?|(?:[a-z0-9]+(?:-[a-z0-9]+)*\.)+[a-z]{2,})$
端口及端口范围校验正则:
^([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])(?:-([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]))?$
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK