Forum Moderators: open
Unless you are thinking of validation that returns an error if the field is less than 6 characters. In that case it's better be done server-side than in JS.
But in JS it could be easily done like this:
In HTML
<form name="address" action="/some/script.pl" onsubmit="return check()">
<input type="text" size="20" name="postal" />
<input type="submit" />
</form>
In <head>
<script type="text/javascript">
function check() {
if (document.forms.address.postal.value.length < 6) {
alert('Postal code should be 6 characters long');
}
}
</script>
1) in <form> tag make handler onsubmit="if(check_length()){return false}
2) write a function check_length() {
if(document.forms[form name].elements[element name].value.length < 6) {
alert("You have to enter at least 6 characters!");
return true
}
else {
return false
}
}
and place it in <head> section or in .js file