Is there any helper function in (ASP).NET library that properly escapes .NET regex patterns to be used in javascript? So that i don't need manually escape +
quantifiers, etc. As far as i understand RegularExpressionAttribute from Data Annotations performs proper translation. Can i reuse it somehow?
-
1I've not used it but msdn.microsoft.com/en-us/library/… may help. Looks like it should take any string from .NET and make it into a valid string in javascript (by escaping stuff, etc.). – Chris Feb 6 '12 at 15:14
Add a comment
|
Escape() is your friend:
string escapedInput = Regex.Escape(input);
Turns, for instance, "a+b"
into "a\+b"
.