Textbox validation on getting phone number

Textbox validation on getting phone number

This below is the Exact Code for Phone number validation using Javascript

//Phone Number Validation

<script language="javascript" type="text/javascript">
function isAlphaNumeric(e) {
var key;

if (window.event) {

key = window.event.keyCode; //IE


else {

key = e.which; //firefox


if (!( (key > 47 && key <= 57) || (key == 8))) {

alert(" You can enter only 0 to 9 and BackSpace ");

return false;

var a = document.getElementById('<%=TxtMobileno.ClientID %>').value;
if (a.length >= 10) {
alert("Please Enter 10 digit Mobile Number");
document.getElementById('<%=TxtMobileno.ClientID %>').focus();
return false;


Then in the Textbox control add the event to call the validation function,

<asp:TextBox ID="TxtMobileno" runat="server" onkeypress="return isAlphaNumeric(event);" ></asp:TextBox>

It works perfect....

Related Articles

More articles: Javascript phone number validation Phone number validation Javascript validation"


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: