JQuery usando velho JavaScript


Exemplo: Validação de e-mail

<!DOCTYPE HTML>
<html>
<head>
   <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>

<input type="email" id="email" />
<br />
<input type="button" id="button" value="validate email"/>
<input type="reset" id="reset"/>

<script type="text/javascript">

    $("#button").click({ value: "email" }, ValidateEmail);
    
    function ValidateEmail(event) {
        ValidateEmailAddress(event.data.value);
    }

    function ValidateEmailAddress(a) {
        var emailRegex = /^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;
        var email = String(document.getElementById(a).value);
        
        if ((undefined !== email) && ("" !== email) && !emailRegex.test(email)) {
         alert("Invalid email address.\nPlease check the value and try again.");
        }
    }
</script>

</body>
</html>


Referência: https://emailregex.com/
Licença CC BY-SA 4.0 Silvia Pinhão Lopes, 26.11.18
Print Friendly and PDF

Sem comentários:

Com tecnologia do Blogger.