Use / Escape @ in CSHTML view

3

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;
            }
        }
    });

And the error that occurs:

    
asked by anonymous 11.09.2015 / 14:55

1 answer

3

To escape, where you have @ put @@ .

Looking like this:

 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";
    
11.09.2015 / 14:59