Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
109
rated 0 times [  115] [ 6]  / answers: 1 / hits: 17000  / 11 Years ago, fri, october 18, 2013, 12:00:00

I am performing email address validation with javascript in a razor view page.
The regex I am going to use is similar to the one proposed at Validate email address in JavaScript?



However, because the regex contains an '@' character, I am getting parser error when try to run the web app.



my regex looks like



/^...otherpart @* ... other part$/


I tried to add an '@' character to make the in the origin regex ... @@* ..., this eliminated the compilation error but seems to make the regex stops working. (we have used it in another web app that does not use razor engine, so I know it works).



Is there any other way to escape the '@' character?


More From » regex

 Answers
33

You can add another @ in front of it to escape @@, try leaving out the quantifer *. If this doesn't seem to work then add <text></text> around the function, it tells Razor to not parse the contents. Alternatively you can put Javascript in a separate file to accomplish your needs.



If for some reason you have multiple @@ in your string, place code blocks ahead @:@@


[#74909] Wednesday, October 16, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
eliasf

Total Points: 703
Total Questions: 97
Total Answers: 129

Location: Chad
Member since Tue, Apr 27, 2021
3 Years ago
;