Use/Escape @ in CSHTML view

Asked

Viewed 100 times

3

I have a jQuery code on the CSHTML page and I’m having trouble validating the email with a regular expression, because the @ is a Razor command in .NET. How to proceed to resolve this issue?

Follows 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: inserir a descrição da imagem aqui

  • As the research does not help I did not find but I’m sure this was asked recently. If I’m not mistaken it was @Gypsy who replied, but I could be wrong.

  • @Bigown In my opinion, that question is already answered.

1 answer

3


To escape where you have @ puts @@.

Thus remaining:

 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";

Browser other questions tagged

You are not signed in. Login or sign up in order to post.