I'm using jquery validate for client side email validation. Of course I also have server side validation and want to use the same regex as jquery does to validate the input on the server side.
我正在使用jquery验证客户端电子邮件验证。当然我也有服务器端验证,并希望使用与jquery相同的正则表达式来验证服务器端的输入。
I found this regex in the source of jquery validate:
我在jquery validate的源代码中发现了这个正则表达式:
// http://docs.jquery.com/Plugins/Validation/Methods/email
email: function( value, element ) {
// contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
return this.optional(element) || /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i.test(value);
},
Note the /i
at the end of the regex to make the whole thing case insensitive.
注意/ iat正则表达式的结尾使整个事件不区分大小写。
I have a complex site with c# libraries Ánd VB libraries.
我有一个带有c#libraries和VB库的复杂站点。
In both libraries I need to implement this email validation.
在这两个库中,我需要实现此电子邮件验证。
In C# I'm using this code:
在C#中我使用此代码:
Regex RegexEmailAddress = new Regex(@"^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$", RegexOptions.Compiled | RegexOptions.Singleline | RegexOptions.IgnoreCase);
Note RegexOptions.IgnoreCase
at the end.
最后注意RegexOptions.IgnoreCase。
However, In my VB code I need a string that hold the regex pattern.
但是,在我的VB代码中,我需要一个包含正则表达式模式的字符串。
Public Const MAIL_REGEX As String = "^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$"
So far I coudn't find any working regex adjustment to make this regex case insensitive.
到目前为止,我还没有找到任何正则表达式调整,以使这个正则表达式不敏感。
I tried adding (?i)
in front of the string but it's logged as invalid regex when using it on my website.
我尝试在字符串前面添加(?i)但在我的网站上使用时它被记录为无效的正则表达式。
also add /i
at the end of the pattern gives an invalid regex.
另外在模式的末尾添加/ i会产生无效的正则表达式。
Update: I tried another method with inline regex modifier I found in this SO question.
更新:我在此SO问题中尝试了另一种使用内联正则表达式修饰符的方法。
Case sensitive: ^[0-9]\s(lbs|kg|kgs)$
Case insensitive: (?i:^[0-9]\s(lbs|kg|kgs)$)
But it's also not working.
但它也没有用。
Here's the javascript error I get:
这是我得到的javascript错误:
Uncaught SyntaxError: Invalid regular expression: /(?i:^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$)/: Invalid group
Update 2
I'm using RegularExpressionValidator
我正在使用RegularExpressionValidator
RegularExpressionValidator rxvalEmail = new RegularExpressionValidator();
rxvalEmail.ID = "rxvalEmail";
rxvalEmail.ValidationExpression = SomeHelperInVB.MAIL_REGEX;
rxvalEmail.ControlToValidate = "txtEmail";
So how can I make my regex case insensitive using a inline regex modifier? Of any other sollution to solve this?
那么如何使用内联正则表达式修饰符使我的正则表达式不区分大小写呢?解决这个问题的任何其他解决方案?
2 个解决方案
#1
1
I made a simple console application and by using (?i) it works just fine:
我做了一个简单的控制台应用程序,并使用(?i)它工作得很好:
Module Module1
Public Const MAIL_REGEX As String = "^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$"
Public Const MAIL_REGEX_I As String = "(?i)^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$"
Sub Main()
Dim r_sensitive As New System.Text.RegularExpressions.Regex(MAIL_REGEX)
Dim r_insensitive As New System.Text.RegularExpressions.Regex(MAIL_REGEX_I)
' Returns true
Console.WriteLine("ok@ok.com: " + r_sensitive.IsMatch("ok@ok.com").ToString)
' Returns false
Console.WriteLine("NOT_ok@ok.com: " + r_sensitive.IsMatch("NOT_ok@ok.com").ToString)
' Returns true
Console.WriteLine("ok@ok.com: " + r_insensitive.IsMatch("ok@ok.com").ToString)
' Returns true
Console.WriteLine("NOT_ok@ok.com: " + r_insensitive.IsMatch("NOT_ok@ok.com").ToString)
Console.Read()
End Sub
End Module
Update: OK, so you are using RegularExpressionValidator to do validation on both client and server. .. Since the syntax is different between VB-RegEx and Javascript-Regex I'm not sure it's possible to do what you want. In VB you use (?i) in the beginning of the expression whereas in Javascript you need to add /i as a modifier when construction the expression (http://www.w3schools.com/jsref/jsref_obj_regexp.asp).
更新:好的,所以您使用RegularExpressionValidator在客户端和服务器上进行验证。 ..由于VB-RegEx和Javascript-Regex之间的语法不同,我不确定它是否可以做你想要的。在VB中,您在表达式的开头使用(?i),而在Javascript中,您需要在构造表达式时添加/ i作为修饰符(http://www.w3schools.com/jsref/jsref_obj_regexp.asp)。
Maybe you need to use another expression, which doesn't require a "case-insensitive modifier". This one is from Expresso (http://www.ultrapico.com/expresso.htm):
也许你需要使用另一个表达式,它不需要“不区分大小写的修饰符”。这个来自Expresso(http://www.ultrapico.com/expresso.htm):
([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})
Or, another option would be to replace [a-z] with [a-zA-Z] in your current expression.
或者,另一种选择是在当前表达式中用[a-zA-Z]替换[a-z]。
Neither of the two expressions works when using Internationalized Domain Names, like "any.name@domännamn.se" (notice the "ä" in the domain name).
当使用国际化域名时,这两个表达式都不起作用,例如“any.name@domännamn.se”(注意域名中的“ä”)。
#2
0
Some information that might could help others:
一些可能有助于他人的信息:
I found out why the regex modifiers aren't working for RegularExpressionValidator when debugging the client side code used for validation.
我在调试用于验证的客户端代码时发现了为什么正则表达式修饰符不适用于RegularExpressionValidator。
The code below shows how client validation for regex is done using RegularExpressionValidator control:
下面的代码显示了如何使用RegularExpressionValidator控件完成正则表达式的客户端验证:
function RegularExpressionValidatorEvaluateIsValid(val) {
var value = ValidatorGetValue(val.controltovalidate);
if (ValidatorTrim(value).length == 0)
return true;
var rx = new RegExp(val.validationexpression); // Error: Invalid regular expression:....
var matches = rx.exec(value);
return (matches != null && value == matches[0]);
}
new RegExp("pattern/i")
will be formatted as: /pattern/i/
新的RegExp(“pattern / i”)格式为:/ pattern / i /
and that's indeed no valid regex. The valid regex would be: /pattern/i
这确实没有正确的正则表达式。有效的正则表达式是:/ pattern / i
=> Conclusion: Modifiers can't work using RegularExpressionValidator. I'll probably write use CustomValidator control instead with custom server and client side code.
=>结论:修饰符无法使用RegularExpressionValidator。我可能会编写使用CustomValidator控件而不是自定义服务器和客户端代码。
Another option would be to replace [a-z]
with [a-zA-Z] in the used regex
另一种选择是在使用的正则表达式中用[a-zA-Z]替换[a-z]
#1
1
I made a simple console application and by using (?i) it works just fine:
我做了一个简单的控制台应用程序,并使用(?i)它工作得很好:
Module Module1
Public Const MAIL_REGEX As String = "^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$"
Public Const MAIL_REGEX_I As String = "(?i)^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$"
Sub Main()
Dim r_sensitive As New System.Text.RegularExpressions.Regex(MAIL_REGEX)
Dim r_insensitive As New System.Text.RegularExpressions.Regex(MAIL_REGEX_I)
' Returns true
Console.WriteLine("ok@ok.com: " + r_sensitive.IsMatch("ok@ok.com").ToString)
' Returns false
Console.WriteLine("NOT_ok@ok.com: " + r_sensitive.IsMatch("NOT_ok@ok.com").ToString)
' Returns true
Console.WriteLine("ok@ok.com: " + r_insensitive.IsMatch("ok@ok.com").ToString)
' Returns true
Console.WriteLine("NOT_ok@ok.com: " + r_insensitive.IsMatch("NOT_ok@ok.com").ToString)
Console.Read()
End Sub
End Module
Update: OK, so you are using RegularExpressionValidator to do validation on both client and server. .. Since the syntax is different between VB-RegEx and Javascript-Regex I'm not sure it's possible to do what you want. In VB you use (?i) in the beginning of the expression whereas in Javascript you need to add /i as a modifier when construction the expression (http://www.w3schools.com/jsref/jsref_obj_regexp.asp).
更新:好的,所以您使用RegularExpressionValidator在客户端和服务器上进行验证。 ..由于VB-RegEx和Javascript-Regex之间的语法不同,我不确定它是否可以做你想要的。在VB中,您在表达式的开头使用(?i),而在Javascript中,您需要在构造表达式时添加/ i作为修饰符(http://www.w3schools.com/jsref/jsref_obj_regexp.asp)。
Maybe you need to use another expression, which doesn't require a "case-insensitive modifier". This one is from Expresso (http://www.ultrapico.com/expresso.htm):
也许你需要使用另一个表达式,它不需要“不区分大小写的修饰符”。这个来自Expresso(http://www.ultrapico.com/expresso.htm):
([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})
Or, another option would be to replace [a-z] with [a-zA-Z] in your current expression.
或者,另一种选择是在当前表达式中用[a-zA-Z]替换[a-z]。
Neither of the two expressions works when using Internationalized Domain Names, like "any.name@domännamn.se" (notice the "ä" in the domain name).
当使用国际化域名时,这两个表达式都不起作用,例如“any.name@domännamn.se”(注意域名中的“ä”)。
#2
0
Some information that might could help others:
一些可能有助于他人的信息:
I found out why the regex modifiers aren't working for RegularExpressionValidator when debugging the client side code used for validation.
我在调试用于验证的客户端代码时发现了为什么正则表达式修饰符不适用于RegularExpressionValidator。
The code below shows how client validation for regex is done using RegularExpressionValidator control:
下面的代码显示了如何使用RegularExpressionValidator控件完成正则表达式的客户端验证:
function RegularExpressionValidatorEvaluateIsValid(val) {
var value = ValidatorGetValue(val.controltovalidate);
if (ValidatorTrim(value).length == 0)
return true;
var rx = new RegExp(val.validationexpression); // Error: Invalid regular expression:....
var matches = rx.exec(value);
return (matches != null && value == matches[0]);
}
new RegExp("pattern/i")
will be formatted as: /pattern/i/
新的RegExp(“pattern / i”)格式为:/ pattern / i /
and that's indeed no valid regex. The valid regex would be: /pattern/i
这确实没有正确的正则表达式。有效的正则表达式是:/ pattern / i
=> Conclusion: Modifiers can't work using RegularExpressionValidator. I'll probably write use CustomValidator control instead with custom server and client side code.
=>结论:修饰符无法使用RegularExpressionValidator。我可能会编写使用CustomValidator控件而不是自定义服务器和客户端代码。
Another option would be to replace [a-z]
with [a-zA-Z] in the used regex
另一种选择是在使用的正则表达式中用[a-zA-Z]替换[a-z]