Click here to Skip to main content
16,013,605 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
dear sir,

i have one textbox and i want to do accept only numbers through this textbox.

HTML
<body>
<form method="POST" action="">

Phone no-<input type="number" name="phone no" maxlength="10"/>
</form>
</body>


plz help...
Posted
Updated 26-Jul-19 3:25am
v2
Comments
Sanket Saxena 29-Apr-14 6:09am    
did u try our best friend - Google?
Nelek 29-Apr-14 6:21am    
I don't think so
Bojjaiah 29-Apr-14 8:40am    
hi Raj, Is this working?

try this javascript function:
function mask(textbox, e) {

      var charCode = (e.which) ? e.which : e.keyCode;
      if (charCode == 46 || charCode > 31&& (charCode < 48 || charCode > 57)) 
         {
            alert("Only Numbers Allowed");
            return false;
         }
     else
         {
             return true;
         }
       }

Call function like this in textbox,
JavaScript
onkeypress="return mask(this,event);"
 
Share this answer
 
v3
Javascript Code:

function allnumeric(inputtxt)
{
var numbers = /^[0-9]+$/;
if(inputtxt.value.match(numbers))
{
alert('Your Registration number has accepted....');
document.form1.text1.focus();
return true;
}
else
{
alert('Please input numeric characters only');
document.form1.text1.focus();
return false;
}
}




HTML Code:

<input type='text' name='text1'/>


<input type="submit" name="submit" value="Submit" onclick="allnumericplusminus(document.form1.text1)" />
 
Share this answer
 
try this

function
PHP
is_numeric(12);
 
Share this answer
 
Comments
Bojjaiah 29-Apr-14 8:40am    
hi Raj, Is this working?
try this javascript function:

function mask(textbox, e) {

            var charCode = (e.which) ? e.which : e.keyCode;
            if (charCode == 46 || charCode > 31
            && (charCode < 48 || charCode > 57)) {
                alert("Only Numbers Allowed");
                return false;
            }
            else
               {
                 return true;
                }
       }
 
Share this answer
 
just simply use html5 control
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900