Example 1: javascript regex email
function validateEmail (emailAdress) { let regexEmail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/; if (emailAdress.match(regexEmail)) { return true; } else { return false; } } let emailAdress = "test@gmail.com"; console.log(validateEmail(emailAdress));
Example 2: form validation for email in js
<script> function validateform(){ var name=document.myform.name.value; var password=document.myform.password.value; if (name==null || name==""){ alert("Name can't be blank"); return false; }else if(password.length<6){ alert("Password must be at least 6 characters long."); return false; } }
Comments
Post a Comment