【发布时间】:2023-03-28 16:16:01
【问题描述】:
我需要一个正则表达式才能在没有 http:// 或 https:// 的情况下验证域名
我的意思:
有效的应该是:
domain.com
domain.fr
domain.it
domain.whateverelse
subdomain.domain.com
subdomain.doamin.fr
subdomain.domain.whateverelse
应该是无效的:
domain
http://domain.com
https://domain.com
https://domain.whateverelse
http://subdomain.domain.com
http://subdomain.domain.fr
http://subdomain.domain.whateverelse
这就是我到目前为止的结果:
(http(s)?://)?([\w-]+\.)+[\w-]+[.com]+(/[/?%&=]*)?
例如,上面的正则表达式认为 domain.whatever 无效......所以基本上只适用于 .com
【问题讨论】:
-
@AvinashRaj:非常接近但不完全:该正则表达式也匹配
domain -
@AvinashRaj:
domain应该是无效的 -
但这将 regex101.com/r/cJ9uZ9/5 工作。
标签: regex asp.net-mvc-5 model-validation