Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What if my javascript variable has the at-sign in its value in mvc3?

I have the following email-validator in my javascript, but the @ is getting misinterpreted in MVC3:

function validateEmail(emailAddress) {   
    var emailPattern = "/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/";
    return emailPattern.test(emailAddress);
} 

Is there a way around this? I've tried using slashes to escape the at sign, but that didn't work.

like image 781
WEFX Avatar asked Jan 25 '26 07:01

WEFX


1 Answers

function validateEmail(emailAddress) {   
    var emailPattern = "/^[a-zA-Z0-9._-]+@@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/";
    return emailPattern.test(emailAddress);
} 

@@ escapes @

like image 119
Steve Elliott Avatar answered Jan 26 '26 19:01

Steve Elliott



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!