Reputation: 15179
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?
Upvotes: 1
Views: 265
Reputation: 19345
Escape() is your friend:
string escapedInput = Regex.Escape(input);
Turns, for instance, "a+b"
into "a\+b"
.
Upvotes: 2