Source Code:
(back to article)
Submit
Result:
Report an issue
<!DOCTYPE html> <html> <head> <title>Titre du document</title> </head> <body> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form> <p>Saisissez une adresse électronique:</p> <input id='email'> <button type='submit' id='validate'>Validate!</button> </form> <h2 id='result'></h2> <script> function validateEmail(email) { var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/; return re.test(email); } function validate() { var $result = $("#result"); var email = $("#email").val(); $result.text(""); if (validateEmail(email)) { $result.text(email + " is valid"); $result.css("color", "blue"); } else { $result.text(email + " is not valid"); $result.css("color", "red"); } return false; } $("#validate").on("click", validate); </script> </body> </html>