Javascript to validate all form fields when onSubmit
function checkrefereremail(){
//var testresults
var nam=document.getElementById('name').value;
var mob=document.getElementById('contactno').value;
var str=document.getElementById('emailid').value;
var anum=/(^\d+$)|(^\d+\.\d+$)/ // integer validation
var flag=1;
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i // email validation
$('#namemsg').html('');$('#mobmsg').html('');$('#emailmsg').html('');$('#captchamsg').html('');
if(nam == '')
{
document.getElementById("namemsg").innerHTML = "Please input a valid name!";
flag++;
}
if (anum.test(mob) == false)
{
document.getElementById("mobmsg").innerHTML = "Please input a valid mobile no!";
flag++;
}
if(filter.test(str) == false){
document.getElementById("emailmsg").innerHTML = "Please input a valid email address!";
flag++;
}else
{
return Captcharesult()
return true;
}
}
</script>
Refer mydala view source:
<script>
function user()
{
var isflag=1;
$('#emailidErr').html('');$('#cpasswordErr').html('');$('#passwordErr').html('');$('#mobilenoErr').html('');$('#dobErr').html('');$('#tcboxErr').html('');$('#captchaErr').html('');
if($('#emailid').val()=='')
{
$('#emailid').addClass("red-border");
$('#emailidErr').html('<p>Please Enter Email Id</p>');
isflag++;
}else{
var emailFilter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; // Both work same:and are userful /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
if(!(emailFilter.test($('#emailid').val())))
{
$('#emailid').addClass("red-border");
$('#emailid').val('');
$('#emailidErr').html('<p>Please Enter Valid Email Id</p>');
isflag++;
}
}
if($('#password').val()=='')
{
$('#password').addClass("red-border");
$('#passwordErr').html('<p>Please Enter Password</p>');
isflag++;
}else{
var Password = $('#password').val();
if(Password.length<6)
{
$('#passwordErr').html('<p>Please Enter Six digit in Password</p>');
$('#password').addClass("red-border");
isflag++;
}
if(Password!=$('#cpassword').val())
{
$('#cpassword').addClass("red-border");
$('#cpasswordErr').html('<p>Please Enter Same Password in Confirm Password</p>');
isflag++;
}
}
if($('#mobileno').val()!='' )
{
if(!($('#mobileno').val().match(/^[0-9]+$/)))
{
$('#mobileno').addClass("red-border");
$('#mobilenoErr').html('<p>Please Enter Numeric Value in Mobile Number!</p>');
isflag++;
}
var Mobile=$('#mobileno').val();
if ((Mobile.length<10))
{
$('#mobilenoErr').html('<p>Please Enter Ten digit in Mobile Number!</p>');
$('#mobileno').addClass("red-border");
isflag++;
}
if ((Mobile.length>10))
{
$('#mobilenoErr').html('<p>Please Enter Ten digit in Mobile Number!</p>');
$('#mobileno').addClass("red-border");
isflag++;
}
}
else
{
$('#mobileno').addClass("red-border");
$('#mobilenoErr').html('<p>Please Enter Your Mobile Number</p>');
isflag++;
}
if($('#cityid').val()=='')
{
$('#cityid').addClass("red-border");
$('#cityidErr').html('<p>Please Select City</p>');
isflag++;
}
if($('#date_dd').val()=="" && $('#date_mm').val()=="" && $('#date_yy').val()=="")
{
if($('#date_dd').val()==""){$('#date_dd').addClass("red-border");}
if($('#date_mm').val()==""){$('#date_mm').addClass("red-border");}
if($('#date_yy').val()==""){$('#date_yy').addClass("red-border");}
$('#dobErr').html('<p>Please Select Date of Birth!</p>');
isflag++;
}
if($('#b_pincode').val()!='' )
{
if(!($('#b_pincode').val().match(/^[0-9]+$/)))
{
$('#b_pincode').addClass("red-border");
$('#b_pincodeErr').html('<p>Please Enter Numeric Value in Zip Code!</p>');
isflag++;
}
var zipcode=$('#b_pincode').val();
if ((zipcode.length<6))
{
$('#b_pincodeErr').html('<p>Please Enter six digit in Zip Code!</p>');
$('#b_pincode').addClass("red-border");
isflag++;
}
if ((zipcode.length>6))
{
$('#b_pincodeErr').html('<p>Please Enter six digit in Zip Code!</p>');
$('#b_pincode').addClass("red-border");
isflag++;
}
}
if($('#captcha').val()==''){
$('#captcha').addClass("red-border");
$('#captchaErr').html('<p>Please Enter Verification code</p>');
isflag++;
}
if(document.form_user.tcbox.checked == false)
{
$('#tcbox').addClass("red-border");
$('#tcboxErr').html('<p>Please accept the T&C.</p>');
isflag++;
}
if(isflag > 1){
$('#loginerror').show();
return false;
}
document.getElementById('form_user').submit();
document.form_user.submit();
}
</script>
function checkrefereremail(){
//var testresults
var nam=document.getElementById('name').value;
var mob=document.getElementById('contactno').value;
var str=document.getElementById('emailid').value;
var anum=/(^\d+$)|(^\d+\.\d+$)/ // integer validation
var flag=1;
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i // email validation
$('#namemsg').html('');$('#mobmsg').html('');$('#emailmsg').html('');$('#captchamsg').html('');
if(nam == '')
{
document.getElementById("namemsg").innerHTML = "Please input a valid name!";
flag++;
}
if (anum.test(mob) == false)
{
document.getElementById("mobmsg").innerHTML = "Please input a valid mobile no!";
flag++;
}
if(filter.test(str) == false){
document.getElementById("emailmsg").innerHTML = "Please input a valid email address!";
flag++;
}else
{
return Captcharesult()
return true;
}
}
</script>
Refer mydala view source:
<script>
function user()
{
var isflag=1;
$('#emailidErr').html('');$('#cpasswordErr').html('');$('#passwordErr').html('');$('#mobilenoErr').html('');$('#dobErr').html('');$('#tcboxErr').html('');$('#captchaErr').html('');
if($('#emailid').val()=='')
{
$('#emailid').addClass("red-border");
$('#emailidErr').html('<p>Please Enter Email Id</p>');
isflag++;
}else{
var emailFilter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; // Both work same:and are userful /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
if(!(emailFilter.test($('#emailid').val())))
{
$('#emailid').addClass("red-border");
$('#emailid').val('');
$('#emailidErr').html('<p>Please Enter Valid Email Id</p>');
isflag++;
}
}
if($('#password').val()=='')
{
$('#password').addClass("red-border");
$('#passwordErr').html('<p>Please Enter Password</p>');
isflag++;
}else{
var Password = $('#password').val();
if(Password.length<6)
{
$('#passwordErr').html('<p>Please Enter Six digit in Password</p>');
$('#password').addClass("red-border");
isflag++;
}
if(Password!=$('#cpassword').val())
{
$('#cpassword').addClass("red-border");
$('#cpasswordErr').html('<p>Please Enter Same Password in Confirm Password</p>');
isflag++;
}
}
if($('#mobileno').val()!='' )
{
if(!($('#mobileno').val().match(/^[0-9]+$/)))
{
$('#mobileno').addClass("red-border");
$('#mobilenoErr').html('<p>Please Enter Numeric Value in Mobile Number!</p>');
isflag++;
}
var Mobile=$('#mobileno').val();
if ((Mobile.length<10))
{
$('#mobilenoErr').html('<p>Please Enter Ten digit in Mobile Number!</p>');
$('#mobileno').addClass("red-border");
isflag++;
}
if ((Mobile.length>10))
{
$('#mobilenoErr').html('<p>Please Enter Ten digit in Mobile Number!</p>');
$('#mobileno').addClass("red-border");
isflag++;
}
}
else
{
$('#mobileno').addClass("red-border");
$('#mobilenoErr').html('<p>Please Enter Your Mobile Number</p>');
isflag++;
}
if($('#cityid').val()=='')
{
$('#cityid').addClass("red-border");
$('#cityidErr').html('<p>Please Select City</p>');
isflag++;
}
if($('#date_dd').val()=="" && $('#date_mm').val()=="" && $('#date_yy').val()=="")
{
if($('#date_dd').val()==""){$('#date_dd').addClass("red-border");}
if($('#date_mm').val()==""){$('#date_mm').addClass("red-border");}
if($('#date_yy').val()==""){$('#date_yy').addClass("red-border");}
$('#dobErr').html('<p>Please Select Date of Birth!</p>');
isflag++;
}
if($('#b_pincode').val()!='' )
{
if(!($('#b_pincode').val().match(/^[0-9]+$/)))
{
$('#b_pincode').addClass("red-border");
$('#b_pincodeErr').html('<p>Please Enter Numeric Value in Zip Code!</p>');
isflag++;
}
var zipcode=$('#b_pincode').val();
if ((zipcode.length<6))
{
$('#b_pincodeErr').html('<p>Please Enter six digit in Zip Code!</p>');
$('#b_pincode').addClass("red-border");
isflag++;
}
if ((zipcode.length>6))
{
$('#b_pincodeErr').html('<p>Please Enter six digit in Zip Code!</p>');
$('#b_pincode').addClass("red-border");
isflag++;
}
}
if($('#captcha').val()==''){
$('#captcha').addClass("red-border");
$('#captchaErr').html('<p>Please Enter Verification code</p>');
isflag++;
}
if(document.form_user.tcbox.checked == false)
{
$('#tcbox').addClass("red-border");
$('#tcboxErr').html('<p>Please accept the T&C.</p>');
isflag++;
}
if(isflag > 1){
$('#loginerror').show();
return false;
}
document.getElementById('form_user').submit();
document.form_user.submit();
}
</script>
0 comments:
Post a Comment