Data Validation for Random varying Phone Numbers

Posted by baron on Stack Overflow See other posts from Stack Overflow or by baron
Published on 2010-05-05T04:07:21Z Indexed on 2010/05/05 4:18 UTC
Read the original article Hit count: 165

Filed under:
|
|
|
|

I am storing phone numbers of varying lengths in my WPF (C#, VS 08) App.

I store them as strings. My question is about my method AddNewPhoneNo(string phoneNo).

In this method, I use Int.TryParse to validate the incoming number (i.e. not null, is numeric...). I've since realized this is probably not the best way to do this, because then I am limited to a number which is ± 2147483647. Definetly this is not always the case with phone numbers.

What is a good, easy way to validate phone numbers? I guess the basic rules would be as follows:

  • All numeric
  • All positive
  • Upto 25 chars (could be more, but this will to do for time being)

Can't thing if theres any more rules at the moment, that's probably it.

© Stack Overflow or respective owner

Related posts about string

Related posts about int