Validate Email ,Date, Mobile Field On Web To Lead Form in Salesforce
Que: Before Creating Web to Lead form Validate Email should be proper format and Date should be dd/mm/yyyy and Mobile No Should be 10 digits.
Solution: Validate Web to Lead form using Javascript/Jquery
<META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8">
<head>
<script type = "text/javascript">
function check()
{
var emailadd = document.getElementById('email').value;
//alert(emailadd);
if(emailadd!= '' && emailadd != null)
{
var str=document.getElementById('email').value;
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (!filter.test(str))
{
alert("Please input a valid email address!");
return false;
}
}
var mobileVale = document.getElementById('mobile').value;
//alert(mobileVale.length);
if(mobileVale!='' && mobileVale!=null)
{
if(mobileVale.length!=10){
alert('Please Enter 10 Digit No');
return false;
}
}
var valuesofDarte = document.getElementById('DateID').value;
if(valuesofDarte!='' && valuesofDarte!=null)
{
//alert(valuesofDarte);
var validformat=/^\d{2}\/\d{2}\/\d{4}$/ //Basic check for format validity
//alert(validformat);
//var returnval=false
if (!validformat.test(valuesofDarte))
{
alert("Invalid Date Format. It should be dd/mm/yyyy.");
return false;
}
else{
//Detailed check for valid date ranges
var dayfield=valuesofDarte.split("/")[0]
var monthfield=valuesofDarte.split("/")[1]
var yearfield=valuesofDarte.split("/")[2]
var dayobj = new Date(yearfield, monthfield-1, dayfield)
if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
{
alert("Invalid Day, Month, or Year range detected. It should be dd/mm/yyyy.");
return false;
}
return true;
}
return true;
}
}
</script>
</head>
<form name="contact-form" method="post" id="footer-formID" action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8">
<input type=hidden name="oid" value="00Dj0000001olle">
<input type=hidden name='retURL' value="http://google.com>
<input type="text" id='first_name' name="first_name" value=""/>
<input type="text" id='last_name' name="last_name" value=""/>
<input type="text" id='email' name="email" value="" />
<input type="text" id='mobile' name="mobile" value="" />
<input id='DateID' name='00Nj0000006KcyE' value=""></
<input type="hidden" name="source" id="sourceId" value="" />
<button type="submit" class="button" onclick="return check();">Send Email</button>
</form>
Solution: Validate Web to Lead form using Javascript/Jquery
<META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8">
<head>
<script type = "text/javascript">
function check()
{
var emailadd = document.getElementById('email').value;
//alert(emailadd);
if(emailadd!= '' && emailadd != null)
{
var str=document.getElementById('email').value;
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (!filter.test(str))
{
alert("Please input a valid email address!");
return false;
}
}
var mobileVale = document.getElementById('mobile').value;
//alert(mobileVale.length);
if(mobileVale!='' && mobileVale!=null)
{
if(mobileVale.length!=10){
alert('Please Enter 10 Digit No');
return false;
}
}
var valuesofDarte = document.getElementById('DateID').value;
if(valuesofDarte!='' && valuesofDarte!=null)
{
//alert(valuesofDarte);
var validformat=/^\d{2}\/\d{2}\/\d{4}$/ //Basic check for format validity
//alert(validformat);
//var returnval=false
if (!validformat.test(valuesofDarte))
{
alert("Invalid Date Format. It should be dd/mm/yyyy.");
return false;
}
else{
//Detailed check for valid date ranges
var dayfield=valuesofDarte.split("/")[0]
var monthfield=valuesofDarte.split("/")[1]
var yearfield=valuesofDarte.split("/")[2]
var dayobj = new Date(yearfield, monthfield-1, dayfield)
if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
{
alert("Invalid Day, Month, or Year range detected. It should be dd/mm/yyyy.");
return false;
}
return true;
}
return true;
}
}
</script>
</head>
<form name="contact-form" method="post" id="footer-formID" action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8">
<input type=hidden name="oid" value="00Dj0000001olle">
<input type=hidden name='retURL' value="http://google.com>
<input type="text" id='first_name' name="first_name" value=""/>
<input type="text" id='last_name' name="last_name" value=""/>
<input type="text" id='email' name="email" value="" />
<input type="text" id='mobile' name="mobile" value="" />
<input id='DateID' name='00Nj0000006KcyE' value=""></
<input type="hidden" name="source" id="sourceId" value="" />
<button type="submit" class="button" onclick="return check();">Send Email</button>
</form>
Comments
Post a Comment