I have try to validate an email like below with jQuery in asp.net mvc like below
<script type="text/javascript">
function validateEmail(sEmail) {
var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
if (filter.test(sEmail)) {
return true;
}
else {
return false;
}
$(document).ready(function() {
$('#create').click(function() {
var sEmail = $('#UserName').val();
if ($.trim(sEmail).length == 0) {
alert('Please enter valid email address');
e.preventDefault();
}
if (validateEmail(sEmail)) {
alert('Email is valid');
}
else {
alert('Invalid Email Address');
e.preventDefault();
}
});
});
});
</script>
While rendering the view i got compilation error Unexpected character '\' in that regex pression.How can i resolve this error?
@
symbol is used by the razor view engine, that's probably throwing something off. stackoverflow.com/questions/4690066/…