I am creating a login page, and i want the username to only have an input of numbers, so it will accept 1000 but if i input 1000t and try to submit the form it should decline it.
I tried doing it a different approach and not allow the user to enter letters at all but when i use my code, it lets me type upto 1 character for some reason. I.e. i can type 1000t but not 1000ttt. If i try to type 1000t followed by a "f" it will replace the t with a f, so ill get 1000f. But i only want numbers to appear
My script:
<script>
function validate(evt){
evt.value = evt.value.replace(/[^0-9]/g,"");
}
</script>
My form:
<form action="customer_login.jsp" method="POST">
Customer Number: <input type="text" name="username" onkeypress="validate(username)" />
<br />
Password: <input type="text" name="password" />
<br />
<input type="submit" value="Login" />
</form>
Edit: I also noticed if i type 1001a and press tab, it removes the a, but if i click onto the password box it keeps the a