2

求助正则大佬

 2 years ago
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.

V2EX  ›  前端开发

求助正则大佬

  baba5 · 21 小时 8 分钟前 · 982 次点击

由于用了 xrender ,表单字段校验全部得用一个正则来配置完成,遇到了一些困难,求助各位大佬,需求如下(主要是第一个):

49fb7a1f746fd7e49102a91072aa57b
提前感谢。

第 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])$


有没有更好的方案,欢迎大佬指教

第 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])$

第 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)))

第 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]))?$

非常感谢评论区各位大佬提供的各种思路和帮助,希望对有相同需求的朋友也有帮助。

第 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]))?$

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK