only allow digits in textfield
Posted: Tue Feb 14, 2006 2:38 am
hi, i'm trying to only allow numbers for my textfield.
right now, my script only notifies when the textfield is left blank. how can i change the codes, so that the textfield only accepts 8 digits (12345678) and nothing else?
right now, my script only notifies when the textfield is left blank. how can i change the codes, so that the textfield only accepts 8 digits (12345678) and nothing else?
Code: Select all
<script type="text/javascript">
//-->
var errormessage = ""
var passme=false
function validate()
{
if(passme){passme=false;return true}
errormessage = ""
Contact()
if (errormessage == "")
{
return (true);
}
else
{
alert(errormessage)
return (false);
}
}
function Contact()
{
var cont_no = window.document.contest.contact_no.value
if (cont_no == "")
{
errormessage = errormessage + "Please enter your contact number.\n"
}
}
</script>