Click here to Skip to main content
15,900,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
sir. i have a textbox in which i want to enter only 10 digit mobile number.. if i am entering 11th digit it not be type.. and if i am try to enter alphabet it not be type on textbox.
Posted
Updated 18-Jun-14 22:45pm
v2
Comments
VICK 20-Jun-14 0:36am    
Do have a look at the following.

http://www.codeproject.com/Questions/242224/how-to-validate-phone-and-mobile-number-in-javascr?arn=129

We can use regular expression to validate phone number.
Try following codes :

JavaScript
function phonenumber(inputtxt)  
{  
  var phoneno = /^\d{10}$/;  
  if(inputtxt.value.match(phoneno))  
  {  
      return true;  
  }  
  else  
  {  
     alert("Not a valid Phone Number");  
     return false;  
  }  
}  


Good luck.
 
Share this answer
 
you can use RegularExpressionValidator
<asp:TextBox runat="server" id="txtNumber" />
<asp:RegularExpressionValidator runat="server" id="rexNumber" controltovalidate="txtNumber" validationexpression="^[0-9]{4}$" errormessage="Please enter a 10 digit number!" />
 
Share this answer
 
v2
C#
function isNumberKey(key) {
    //getting key code of pressed key
    var keycode = (key.which) ? key.which : key.keyCode;
    //comparing pressed keycodes

    if (keycode > 31 && (keycode < 48 || keycode > 57) && keycode != 47) {
        alert(" You can enter only characters 0 to 9 ");
        return false;
    }
    else return true;
}


<asp:textbox runat="server" id="txtNumber" maxlength="10" xmlns:asp="#unknown" />
 
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