The html code is
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form> <p>Enter email:</p> <input id='email'> <button type='submit' onclick='validateEmail()'>Check Email</button> </form>
Now when the button is clicked then the JavaScript function validateEmail() will be called. The bellow code in this function. Using regular expressions is probably the best way.
function validateEmail(){ var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; var email = document.getElementById('email').value; if (reg.test(email) == false) { alert("Invalid Email Address"); return false; } }
You might also like:
Simple Array Sum | Javascript | hackerrank.com07-05-2020 hackerrank.com javascript arrays array sum |
Compare the Triplets | Javascript | hackerrank.com07-05-2020 hackerrank.com |
How To Get Your Blogs Posts Using Blogger API30-07-2017 blogger api json php |
Remove last two characters from given string06-03-2017 substring javascript remove |
How to find Angular Errors06-03-2017 errors angularjs exceptionHandler |