Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC4 Razr throws error on AngularJS email regex pattern

Within my MVC4 view, I'm using AngularJS to validate my form fields. Everything works great except for the email validation. I'm using AngularJS v1.2.26 within MVC4 project. Here's the regex pattern I'm using.ng-pattern="/^[_a-z0-9]+(\.[_a-z0-9]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/". My problem is I receive a runtime error in browser when Razr hits the '@' symbol in the regex pattern and the page blows up. Any help would be great. Thanks!

like image 559
Jason Spence Avatar asked Jan 25 '26 04:01

Jason Spence


1 Answers

@ is a special symbol in Razor syntax. To use it on the page just use a double @@ like this:

ng-pattern="/^[_a-z0-9]+(\.[_a-z0-9]+)*@@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/"
like image 156
DavidG Avatar answered Jan 26 '26 19:01

DavidG



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!