質問

Im having quite some trouble with figuring out how to handle this case.. I have a RegExpValidator control that takes a regexp as a value for an attribute (this is in my markup/html code).. and this regexp contains both ' and "..which then of course would cause quite alot of confusion for the .Net compiler and mostlikelyt for the browsers html-engine as well.. So.. My question is.. is there anyway to use a regexp like that inside the html/markup?

Here is the current code:

<MyCustomControl:RegularExpressionValidator Runat="server" ID="EmailRegExpValidator" ResourceID="UserAdministration.EmailRegularExpressionValidator" ControlToValidate="EmailTextBox" ValidationExpression="^((?>[a-zA-Z\d!#$%&'*+\-/=?^_`{|}~]+\x20*|"((?=[\x01-\x7f])[^"\\]|\\[\x01-\x7f])*"\x20*)*(?<angle><))?((?!\.)(?>\.?[a-zA-Z\d!#$%&'*+\-/=?^_`{|}~]+)+|"((?=[\x01-\x7f])[^"\\]|\\[\x01-\x7f])*")@(((?!-)[a-zA-Z\d\-]+(?<!-)\.)+[a-zA-Z]{2,}|\[(((?(?<!\[)\.)(25[0-5]|2[0-4]\d|[01]?\d?\d)){4}|[a-zA-Z\d\-]*[a-zA-Z\d]:((?=[\x01-\x7f])[^\\\[\]]|\\[\x01-\x7f])+)\])(?(angle)>)$" Display="Dynamic"/>

The control is most likely not that custom.. and some how inherits the default regexp validator.

Thanks in advance!

役に立ちましたか?

解決

Because the value side is surrounded by double quotes, you can't use a double quote inside the value. however you can use the unicode equivalent of a double quote \x22 inside the value.

So your ValidationExpression attribute value would look something like:

ValidationExpression="^((?>[a-zA-Z\d!#$%&'*+\-/=?^_`{|}~]+\x20*|\x22((?=[\x01-\x7f])[^\x22\\]|\\[\x01-\x7f])*\x22\x20*)*(?<angle><))?((?!\.)(?>\.?[a-zA-Z\d!#$%&'*+\-/=?^_`{|}~]+)+|\x22((?=[\x01-\x7f])[^\x22\\]|\\[\x01-\x7f])*\x22)@(((?!-)[a-zA-Z\d\-]+(?<!-)\.)+[a-zA-Z]{2,}|\[(((?(?<!\[)\.)(25[0-5]|2[0-4]\d|[01]?\d?\d)){4}|[a-zA-Z\d\-]*[a-zA-Z\d]:((?=[\x01-\x7f])[^\\\[\]]|\\[\x01-\x7f])+)\])(?(angle)>)$"
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top