asp.net 允许 Url 中包含德语字符
我使用带有
[http(s)?://]*([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
正则表达式的 RegularExpressionValidator
控件来验证 Url。我需要允许使用德语字符
(ä,ä,É,é,ö,Ö,ü,Ü,ß)
网址中的 。允许这些字符的精确正则表达式应该是什么?
I am using RegularExpressionValidator
control with
[http(s)?://]*([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
regular expression to validate Url. I need to allow german characters
(ä,Ä,É,é,ö,Ö,ü,Ü,ß)
in Url. What should be exact regular expression to allow these characters?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我希望您知道使用正则表达式进行 URL 验证并不容易,因为 URL 有许多有效的变体。例如,请参阅此
首先你的正则表达式有几个缺陷(这是快速检查后的结果,可能不完整)
参见这里在线检查Regexr
不匹配
为什么只允许
\w 和
-
?但它确实匹配
你在开头定义了一个字符组
[http(s)?://]
意味着匹配里面的任何字符(你可能想要(?:http(s)?://)
和?
代替*
要回答您的问题:
创建一个角色 起来,并将其放在您想要允许的位置。
。将这些字母组合
提示
字符组内的
-
必须位于开头或结尾,否则需要转义。其他 code>(s)? 是
s?
I hope you are aware that it is not easy to use regex for URL validation, because there are many valid variations of URLs. See for example this question.
First your regex has several flaws (this is only after a quick check, maybe not complete)
See here for online check on Regexr
It does not match
Why do you allow only
\w
and-
after the first dot?but it does match
You define a character group at the beginning
[http(s)?://]
what means match any of the characters inside (You probaly want(?:http(s)?://)
and?
after wards instead of*
.To answer your question:
Create a character group with those letters and put it where you want to allow it.
Use it like this
Other hints
The
-
inside of a character group has to be at the start or the end or needs to be escaped.(s)?
iss?