It is important to validate the form submitted by the user because it can have inappropriate values. So validation is must.
Form validation is required to prevent web form malicious users
Most of the web developers prefer JavaScript form validation because processing will be faster than server-side validation
Improper validation of data in the form is one of the main causes of security vulnerabilities. Example
<html>
<body>
<script>
function validateform(){
var name=document.myform.name.value;
var password=document.myform.password.value;
if (name==null || name==""){
alert("Name can't be blank");
return false;
}else if(password.length<6){
alert("Password must be at least 6 characters long.");
return false;
}
}
</script>
<body>
<form name="myform" method="post" onsubmit="return validateform()" >
Name: <input type="text" name="name"><br/>
Password: <input type="password" name="password"><br/>
<input type="submit" value="register">
</form>
</body>
</html>
0 Comment(s)