Click here to Skip to main content
15,891,670 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to validate sri lanka telephone number in asp.net textbox?

Sri lanka tekephone number format
To Fixed telephone
+94 xx zzzzzzz format
To Mobile phone
+94 xx y zzzzzz
Posted
Updated 11-Oct-12 23:54pm
v3
Comments
Bhushan Shah1988 12-Oct-12 5:51am    
Please provide some more information.
bbirajdar 12-Oct-12 5:52am    
What is the format of phone number? How many digits? What is the ISD code ?
Hasiya 12-Oct-12 6:02am    
94
Hasiya 12-Oct-12 5:54am    
Sri lanka tekephone number format
To Fixed telephone
+94 xx zzzzzzz format
To Mobile phone
+94 xx y zzzzzz
bbirajdar 12-Oct-12 6:04am    
okay

1 solution

You can use from the ASP.Net Validators available. You can make use of RegularExpression validator or may be custom validator for this purpose.

Also take a look at MaskedTextBox from the AjaxToolkit if that suits you.

Alternative: You can also do it using javascript. call following javascript function on button click.
JavaScript
function Validate()
{
  var x = document.getElementById("txtPhomenumber").value;
  if(isNaN(x)|| x.indexOf(" ")!=-1)
  {
     alert("Enter numeric value");
     return false;
  }
  if (x.length > 10 || x.length > 8 )
  {
     alert("enter 10 or 8 characters");
     return false;
  }
  if (x.charAt(0)!="9")
  {
      alert("it should start with 9 or 2 ");
      return false;
  }
}

for more detail check, JavaScript: A Quick Check[^]
Validate Phone Numbers: A Detailed Guide[^]
 
Share this answer
 
v2
Comments
bbirajdar 12-Oct-12 6:11am    
Correct +5
Prasad_Kulkarni 12-Oct-12 6:30am    
Thank you Mr. Birajdar
Hasiya 12-Oct-12 6:13am    
I Want to this type of anser??

<asp:TextBox ID="txtPhone" runat="server">
<asp:RegularExpressionValidator
ID="regPhone"
runat="server"
ControlToValidate="txtPhone"
ValidationExpression="^(\(?\s*\d{3}\s*[\)\-\.]?\s*)?[2-9]\d{2}\s*[\-\.]\s*\d{4}$"
Text="Enter a valid phone number" />
Prasad_Kulkarni 12-Oct-12 6:32am    
Why you din't mentioned it in your question itself? Please, follow the last link of my answer you can get different validation expressions there, which will surely help you out. And, do remember if you post your code snippets in your question you will definitely get exact answers.
bbirajdar 12-Oct-12 7:32am    
You just asked - "how to validate sri lanka telephone number in asp.net textbox?" and this is the correct ansxwer....If you want something specific then you should mention that in your question before we waste our time on you...I will not waste more time on you.. The question is closed for me...

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