Forum Moderators: open

Message Too Old, No Replies

Minimum size of text field

How to set minum size of password field

         

powerslave

1:49 pm on Jun 12, 2005 (gmt 0)

10+ Year Member



How do u set the text field to make it so u cant enter less than 6 characters into a certain field?

Thanx

moltar

2:22 pm on Jun 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



if you think about - it's logically impossible.

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>

Moby_Dim

2:34 pm on Jun 12, 2005 (gmt 0)

10+ Year Member



write something like this:

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