I have created 5 validation function.they work induvisually but whwn i call them in a function Validation and call it on form onsubmit.there is an error that submit the form while user entered wrong mob no in textbox.
function Validation() {
RequireFieldValidation();
allLetter();
PasswardValidation();
EmailValidation();
MobValidation();
// if (RequireFieldValidation() == true && allLetter() == true && PasswardValidation() == true && EmailValidation() == true && MobValidation() == true) {
// return true;
// }
// else {
// return false;
// alert("error");
// }
}
function RequireFieldValidation() {
for (var i = 1; i <= 8; i++) {
var name = document.getElementById("TextBox" + i).value;
if (name == "" || name == null) {
alert("Please Enter required info in textbox "+i);
return false;
}
}
//return true;
}
function allLetter()
{
//var n = document.testJavascript.TextBox1;
var name = document.getElementById("TextBox1");
var letters = /^[A-Za-z]+$/;
if (!(name.value.match(letters))) {
alert("Please enter only alphabetic character")
return false;
}
else
{
//return false;
}
}
function PasswardValidation() {
var pwd = document.getElementById("TextBox3").value;
var rpwd = document.getElementById("TextBox4").value;
var len = pwd.length;
if (len <= 5 || len >= 11) {
alert("Please Enter Passward 6 to 10 character long");
return false;
}
else if (pwd != rpwd) {
alert("Passward doesnot match");
return false;
}
else {
// return true;
}
}
function EmailValidation() {
//var n = document.testJavascript.TextBox1;
var email = document.getElementById("TextBox5");
var mailFormate = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if (!(email.value.match(mailFormate)))
{
alert("Please enter correct email-id")
return false;
}
else
{
//return true;
}
}
function MobValidation() {
//var n = document.testJavascript.TextBox1;
var mob = document.getElementById("TextBox6");
if (isNaN(mob.value)) {
alert("Mobile no. contain incorrect character");
return false;
mob.focus();//iske liye variable mob me only getelementbyid chahiye na ki uski value.
}
else if(mob.value.length!=10){
alert("Please enter 10 digit mob no.")
mob.focus();
return false;
}
return true;
}
<form id="form1" runat="server" onsubmit="Validation()" method="post" name="testJavascript" action="#">