yazan3000
asked on
entering numbers only
hi experts..
i have form with text box and i want to make user enter numbers only, when user enters non numbers an error message should appear.
any idea ?
i have form with text box and i want to make user enter numbers only, when user enters non numbers an error message should appear.
any idea ?
<INPUT type="text" name="numeric" maxlength="8" onkeyup='this.value=this.v alue.repla ce(/[^\d]* /gi,"");' />
The above will prevent the user from entering non-numeric characters, so there is no need for an error message box.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
or in a function
<script>
function numericOnly(objText, iFlag){
regEx=/[^\d]/gi
if(regEx.test(objText.valu e)){
if(iFlag){
alert("Invalid Character");
}
objText.value=objText.valu e.replace( /[^\d]*/gi ,"");
}
}
</script>
can be call from any input as
<INPUT type="text" name="numeric" maxlength="8" onkeyup="numericOnly(this, 1)">
give alert
or
<INPUT type="text" name="numeric" maxlength="8" onkeyup="numericOnly(this, 0)">
no alert
<script>
function numericOnly(objText, iFlag){
regEx=/[^\d]/gi
if(regEx.test(objText.valu
if(iFlag){
alert("Invalid Character");
}
objText.value=objText.valu
}
}
</script>
can be call from any input as
<INPUT type="text" name="numeric" maxlength="8" onkeyup="numericOnly(this,
give alert
or
<INPUT type="text" name="numeric" maxlength="8" onkeyup="numericOnly(this,
no alert
thans for the points