javascript validation in aspx file.
what are the wrong in this code.form is submited to server even user enter wrong input.
And dont know which place are good to call below function:form onsubmit or button onclick.
<script language="javascript" type="text/javascript">
function RequireFieldValidation() {
var name = document.getElementById("TextBox1").value;
var letters = /^[A-Za-z]+$/;
var username = document.getElementById("TextBox2").value;
var pwd = document.getElementById("TextBox3").value;
var rpwd = document.getElementById("TextBox4").value;
var len = pwd.length;
var email = document.getElementById("TextBox5");
var mailFormate = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
var mob = document.getElementById("TextBox6");
if (name == "" || name == null) {
alert("Please Enter your Name");
name.focus;
TextBox1.Text == "";
return false;
}
if (!(name.value.match(letters))) {
alert("Name can be only alphabetic");
name.focus;
TextBox1.Text == "";
return false;
}
if (username == "" || username == null) {
alert("Please enter your User Name");
username.focus;
TextBox2.Text == "";
return false;
}
if (pwd == "" || pwd == null) {
alert("Please enter your Passward");
pwd.focus;
TextBox3.Text == "";
return false;
}
if (len <= 5 || len >= 11) {
alert("Please Enter Passward only 6 to 10 character long");
pwd.focus;
TextBox3.Text == "";
return false;
}
if (rpwd == "" || rpwd == null) {
alert("Please enter your Retype Passward");
rpwd.focus;
TextBox4.Text == "";
return false;
}
if (pwd != rpwd) {
alert("Passward doesnot match");
rpwd.focus;
TextBox4.Text == "";
return false;
}
if (email == "" || email == null) {
alert("Please enter your Retype Passward");
email.focus;
TextBox5.Text == "";
return false;
}
if (!(email.value.match(mailFormate))) {
alert("Please enter correct email-id")
email.focus;
TextBox5.Text == "";
return false;
}
if (mob == "" || mob == null) {
alert("Please enter your mobile no.");
mob.focus;
TextBox6.Text == "";
return false;
}
if (isNaN(mob.value)) {
alert("Mobile no. contain incorrect character");
mob.focus;
TextBox6.Text == "";
return false;
}
if (mob.value.length != 10) {
alert("Please enter only 10 digit mob no.")
mob.focus();
TextBox6.Text == "";
return false;
}
return true;
}
</script>
<input id="Submit1" type="submit" value="submit" onclick="return RequireFieldValidation()"/>