Click here to Skip to main content
15,881,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am developing a windows form application in .net c#, All I want to know is how to validate the Indian phone number, if a user inputs in a textbox.
Posted
Updated 21-Nov-21 16:59pm
Comments
Sergey Alexandrovich Kryukov 1-Mar-12 5:15am    
Is it because of using Indo-Arabic numerals? Or is it more simple?
--SA

1) first you create range validator from validation control in toolbox.

2) After that which textbox in need phoneno that textbox rightclick and goto properties see a)min value fix=0, max value=9, Error msg=Enter correct format and control to validator that textbox id. That solve
 
Share this answer
 
I think it may help you....

Validate user input in Windows Forms[^]
 
Share this answer
 
Comments
zainemma 1-Mar-12 4:57am    
Thanks ramuAlla, that helped me a lot, Cheers!!!
Member 10290905 3-Jan-14 4:32am    
i need to phone number validation in c# please help me i new in window application
Use either Regular Expressions or masked textBox.

You should trust your googling skills as well.
 
Share this answer
 
Comments
zainemma 1-Mar-12 4:57am    
Thanks for that answer friend, that was Useful.
thatraja 1-Mar-12 7:51am    
Reg expression is right choice, My 5!
C#
System.Text.RegularExpressions.Regex expr;

        public bool email(string email)
        {
            expr =new  Regex(@"^[a-zA-Z][\w\.-]{2,28}[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$");
            if (expr.IsMatch(email))
            {
                return true;
            }
            else return false;
        }
        public bool phone(string no)
        {
            expr = new Regex(@"^((\+){0,1}91(\s){0,1}(\-){0,1}(\s){0,1}){0,1}9[0-9](\s){0,1}(\-){0,1}(\s){0,1}[1-9]{1}[0-9]{7}$");
            if (expr.IsMatch(no))
            {
                return true;
            }
            else return false;
        }
 
Share this answer
 
private void mobile_Validated(object sender, EventArgs e)
{
errorProvider2.SetError(mobile, "");
}
public bool ValidMobile(string mobileno, out string errorMessage1)
{

Regex ph = new Regex("^[7-9][0-9]{9}$");
if (ph.IsMatch(mobileno))
{
errorMessage1 = "";
return true;
}
errorMessage1 = "Mobile number must be valid...";
return false;

}


private void mobile_Validating(object sender, CancelEventArgs e)
{
if (!ValidMobile(mobile.Text, out string errorMsg))
{

e.Cancel = true;
mobile.Select(0, mobile.Text.Length);

this.errorProvider2.SetError(mobile, errorMsg);

}
}
 
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