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:
Detect AdBlock with JavaScript in my browser30-07-2017 AdBlock javascript detect |
How to get current date and time (yyyy-mm-dd H:i:s) using javascript09-03-2017 javascript date time |
Get previous date from given date in javascript06-03-2017 date javascript previous date |
Filter for change Date Time format (MM-dd-yyyy HH:mm) in Angular Js05-03-2017 mm-dd-yyyy HH:MM date formats angular js |
Send Mail in Node Js21-02-2017 node js mail npm module |