Issue
im am a newbie to javascript, i write a code to add a validation to my form, this is my script:
function validateForm()
{
var name=document.forms["form"]["entry.1017659850"].value;
var email=document.forms["form"]["entry.808043133"].value;
var check=document.forms["form"]["entry.317648050"].checked;
if(name == ""){
document.getElementById("alertname").style.display="block";
return false;
}
if(email == ""){
document.getElementById("alertemail").style.display="block";
return false;
}
if(!check){
document.getElementById("alertcheck").style.display="block";
return false;
}
return true;
}
And i want to add my email validation
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);
}
The question is how will i do it, i am not familiar with the functions on javascript.
Thank you.
Solution
Try this:
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 validateForm()
{
var name=document.forms["form"]["entry.1017659850"].value;
var email=document.forms["form"]["entry.808043133"].value;
var check=document.forms["form"]["entry.317648050"].checked;
if(name == ""){
document.getElementById("alertname").style.display="block";
return false;
}
if(email == ""){
document.getElementById("alertemail").style.display="block";
return false;
}
if(!check){
document.getElementById("alertcheck").style.display="block";
return false;
}
if(!validateEmail(email)){
document.getElementById("alertemail").style.display="block";
return false;
}
return true;
}
Answered By - Alveoli
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.