For my studies I need to create a simple script that checks if the entered data (suppose to be a 5 digit zip code) actually has 5 digits. If more or less then 5 digits entered, a alert should pop up.
So far I managed to get the alert for more and less then a 5 digit entry, but even when entering 5 digits, the alert will come up as well.
Since js is not my favourite subject I am lost, even tho it seems to be a simple thing.
Thanks in advance for answers and hints.
<script type="text/javascript">
<!--
function CheckZip ()
{
var content = document.forms['zipfield'].Field.value;
var length = content.length;
if (length >=5) (alert('Please enter a 5 digit zip code!'));
else if (length <=5) (alert('Please enter a 5 digit zip code!'));
else (length ==5) (alert('Valid entry'))
}
//-->
</script>
</head>
<body>
<div align="left">
<p>Please enter a 5 digit zip code</p>
<form name="zipfield" action="post"><input name="Field" size="5">
<br />
<br />
<input name="check" value="Check entry" onclick="CheckZip()" type="submit">
</form>
<=or>=a number.