function checkEmail() {
var email = document.getElementById('txtEmail');
var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
if (!filter.test(email.value)) {
alert('Please provide a valid email address');
email.focus;
return false;
}
}
- Call the function on Email textbox
/**
* verifie si la chaine renseigné est un email
* check if email is valide
* @param string emailAdress
* @return bool
*/
function isEmail(emailAdress){
let regex = /^w+([.-]?w+)*@w+([.-]?w+)*(.w{2,3})+$/;
if (emailAdress.match(regex))
return true;
else
return false;
}
//see https://regexr.com/3e48o for another exemple
<script language="javascript">
function checkEmail() {
var email = document.getElementById('txtEmail');
var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
if (!filter.test(email.value)) {
alert('Please provide a valid email address');
email.focus;
return false;
}
}</script>
//! check email is valid
function checkEmail(email) {
const re =
/^(([^<>()[].,;:s@"]+(.[^<>()[].,;:s@"]+)*)|(".+"))@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}])|(([a-zA-Z-0-9]+.)+[a-zA-Z]{2,}))$/;
if (re.test(email.value.trim())) {
console.log('email is valid')
} else {
console.log('email is not valid')
}
}
function validateEmail(email) {
var re =
/^(([^<>()[].,;:s@"]+(.[^<>()[].,;:s@"]+)*)|(".+"))@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}])|(([a-zA-Z-0-9]+.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}
function validatePhone(phone) {
// 880-1710-336617 or 8801710336617
var re = /^(?:(?:+|00)88|01)?d{11}$/;
return re.test(phone);
}
function validate() {
document.getElementById('email_error').innerHTML = "";
field = $('#email_phone').val();
//If not an email AND not a phone
if (validateEmail(field)) {
//alert('Email Passed');
//onChange();
document.getElementById('email').value = document.getElementById('email_phone').value;
document.getElementById('phone').value = "";
//return true;
} else if (validatePhone(field)) {
//alert('Phone Passed');
document.getElementById('phone').value = document.getElementById('email_phone').value;
document.getElementById('email').value = "";
//return true;
} else {
//alert('Email or Phone Error');
document.getElementById('email').value = "";
document.getElementById('phone').value = "";
let text;
text = "<strong><span style='color:red'> Email or Phone number Invalid</span></strong>";
document.getElementById("email_error").innerHTML = text;
return false;
}
// Password Match
var password = document.getElementById('password').value;
var confirm_password = document.getElementById('password_confirm').value;
document.getElementById("password_error").innerHTML="";
if(password==""){
document.getElementById("password_error").innerHTML="Please enter password";
return false;
}
if (password != confirm_password) {
let text1;
text1 ="<strong><span style='color:red'>The password and its confirm are not the same </span></strong>";
document.getElementById("password_match").innerHTML = text1;
return false;
}
// Clear Email field value if change
$("#email_phone").change(function() {
document.getElementById('email').value = "";
});
// Clear Phone field value if change
$("#email_phone").change(function() {
document.getElementById('phone').value = "";
});
$("#email_phone").change(function() {
document.getElementById('password_error').value = "";
});
}
<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;
}
}