circlemaker
Programmer
Hellom
I'm using a regular expression to try and determine if a value entered is valid. The value has to be a number and it has to be exactly 8 numbers in length:
12345678 = valid
11111111 = valid
1234567 = invalid
121212121 = invalid
1234567a = invalid
The code I'm using is below, but it won't work. It determines if the values entered are numeric OK, but if I type in more than 8 numbers it still says its valid
<script language="javascript">
function validate() {
eNo = document.all('name1').value;
if(eNo.match(/[0-9]{8}/)) {
alert("valid");
}
else {
alert("invalid");
}
}
</script>
<form id="Form1" method="post">
<input type="text" name="name1" value=""/>
<input type="button" name="btn" value="Button" onclick="javascript:validate();"/>
</form>
Any help would be appreciated as I stuck on this one.
Thanks
Si
I'm using a regular expression to try and determine if a value entered is valid. The value has to be a number and it has to be exactly 8 numbers in length:
12345678 = valid
11111111 = valid
1234567 = invalid
121212121 = invalid
1234567a = invalid
The code I'm using is below, but it won't work. It determines if the values entered are numeric OK, but if I type in more than 8 numbers it still says its valid
<script language="javascript">
function validate() {
eNo = document.all('name1').value;
if(eNo.match(/[0-9]{8}/)) {
alert("valid");
}
else {
alert("invalid");
}
}
</script>
<form id="Form1" method="post">
<input type="text" name="name1" value=""/>
<input type="button" name="btn" value="Button" onclick="javascript:validate();"/>
</form>
Any help would be appreciated as I stuck on this one.
Thanks
Si