I'm having a jQuery code on the CSHTML page and I'm having trouble validating the email with a regular expression since @
is a Razor command in .NET. How do I resolve this problem?
Follow the script:
$("#formEsqueceuSenha").submit(function(event) {
$(".message").hide();
$(".Error").hide();
var sEmail = $("#email").val();
if ((sEmail == '') || (sEmail == null)) {
$("#email").focus();
$(".message")
.text('Por favor, informe um email válido.')
.show();
event.preventDefault();
} else {
var filtro = "/^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i";
if (!filtro.test(sEmail)) {
$("#email").focus();
$(".message")
.text('E-mail digitado esta invalido. Por favor corrigir.')
.show();
event.preventDefault();
} else {
return;
}
}
});