Search This Blog

Saturday, April 6, 2013

Javascript validations

Email Validation

var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
var b=emailfilter.test(document.form2.mailid.value);
if(b==false)
{
alert("Please Enter a valid Mail ID");
document.form2.mailid.focus();
return false;
}

Password Validation

var a = document.form.pass.value;
if(a=="")
{
alert("Please Enter Your Password");
document.form.pass.focus();
return false;
}
if ((a.length < 6) || (a.length > 20))
{
alert("Your Password must be 6 to 20 Character");
document.form.pass.select();
return false;
}

Mobile number Validation

var a = document.form.phone.value;
if(a=="")
{
alert("please enter your mobile no");
document.form.phone.focus();
return false;
}
if(isNaN(a))
{
alert("Enter the valid Mobile Number(Like : 9999911111)");
document.form.phone.focus();
return false;
}
if((a.length < 10) || (a.length > 10))
{
alert(" Your Mobile Number must be 10 Integers");
document.form.phone.select();
return false;
}

Gender Validation

ErrorText= "";
if ( ( form.gender[0].checked == false ) && ( form.gender[1].checked == false ) )
{
alert ( "Please choose your Gender: Male or Female" );
return false;
}
if (ErrorText= "") { form.submit() }
}



1 comment:

  1. Hitesh's blogs break down complex topics like state management and navigation in ASP.NET in an easy-to-understand way. The examples are really helpfulhttps://hiteshnet.blogspot.com/2013/04/javascript-validations.html#comment-form

    ReplyDelete