473,385 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Address and phone validation

Hey guys,
i have a small question in C#. I have a windows form which has Address
fields, zip code and phone number fields. it is working fine with U.S. but i
need to modify that for all the other countries. is there any way i can
validate zipcode and phone numbers.... Thanks in advance.
bye
Srinivas
Nov 16 '05 #1
4 11695
Srinivas,

You should be able to determine the locale of where the app is running and
then choose the correct regular expression to validate the field. I have
posted a couple of links below to help you along the way.

Hope this helps.
--------------------

http://msdn.microsoft.com/library/de...geelements.asp

http://msdn.microsoft.com/library/de...asp?frame=true

Nov 16 '05 #2
thanks for quick response. i didnt get much help from the links u sent. what
i need to do is, if some one selects a country suppose 'china' we need to
validate the format of zip code for china. and the same with phone number..
thanks in advance
srinivas

"Brian Brown" <Br********@discussions.microsoft.com> wrote in message
news:E3**********************************@microsof t.com...
Srinivas,

You should be able to determine the locale of where the app is running and
then choose the correct regular expression to validate the field. I have
posted a couple of links below to help you along the way.

Hope this helps.
--------------------

http://msdn.microsoft.com/library/de...geelements.asp
http://msdn.microsoft.com/library/de...asp?frame=true

Nov 16 '05 #3
> Hey guys,
i have a small question in C#. I have a windows form which has Address
fields, zip code and phone number fields. it is working fine with U.S. but
i
need to modify that for all the other countries. is there any way i can
validate zipcode and phone numbers.... Thanks in advance.


Create a class similar to NumberFormatInfo to contain regular expressions
for validating phone numbers, zip codes and similar. Create one instance for
every single culture your targeting and store the instance in an Hashtable
using the culture as the key. When validating an address retrieve the
correct "address info" object from the hashtable and use the regular
expressions to validate the different fields.

You will have to do some research to gather zip-code and telephone number
validation rules for all of the cultures though...

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
Nov 16 '05 #4
Srinivas,

I am sorry that the links that I provided did not help you. So I have
posted a code sample below to expand on the post that provided earlier. To
simplify the example I am using US date format and British date format to
validate against. To execute the example create a console application and
copy and paste the code below. Watch out for any line wrap. If you have any
questions please reply to this post.

I hope this helps!
--------------------------

using System;
using System.Collections;
using System.Globalization;
using System.Text.RegularExpressions;

namespace ResourceRegExpTest
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
//set up the Current Culture of this thread
string strCulture = CultureInfo.CurrentCulture.Name;
//set up the regular expressions associated with the culture (these are
for date
Hashtable CultRegExp = new Hashtable();
CultRegExp.Add("en-US",@"(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[-
/.](19|20)\d\d"); //English-US (mm/dd/yyyy)
CultRegExp.Add("en-GB",@"(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[-
/.](19|20)\d\d"); //English - United Kingdom (dd/mm/yyyy)

//get a date from the console input
Console.Write("Please enter a date: " );
string strDate = Console.ReadLine();

//get the current culture of the thread
if(CultRegExp.ContainsKey(strCulture))
if(Regex.IsMatch(strDate,CultRegExp[strCulture].ToString()))
Console.WriteLine("The string entered was a date match to the culture:
" + strCulture);
else
Console.WriteLine("The string entered was NOT a match to the culture: "
+ strCulture);
else
Console.WriteLine("There was no match in the hashtable for the culture:
" + strCulture);
}
}
}
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
by: Dynamo | last post by:
Hi The following script was taken from John Coggeshall's (PHP consultant) in his article on Zends site at http://www.zend.com/zend/spotlight/ev12apr.php // Get the email address to validate...
21
by: AnnMarie | last post by:
<script language="JavaScript" type="text/javascript"> <!-- function validate(theForm) { var validity = true; // assume valid if(frmComments.name.value=='' && validity == true) { alert('Your...
5
by: Kamaluokeakua | last post by:
I have to write an application that deals with clients in multiple countries. The addresses, phone numbers, country id and currency information has to be stored into a database that allows for the...
2
by: Sharon Traineanu via .NET 247 | last post by:
I'm using C#.net. I have a phone number in three asp textboxes. I'd like to make the phone number required, and validate to make sure only numbers have been entered. My main problem is I can't...
1
by: cemcat | last post by:
Hello, We have an ASP.NET 2.0 (C#) web form that contains a textbox for users to enter multiple e-mail addresses separated by semicolons. We need to validate that each individual e-mail address...
8
by: prabhuram.k | last post by:
Can anybody know how to validate IPV4 and IPV6 address in C++
10
by: JackM | last post by:
I'm still working on validating the phone numbers that are entered on a form but have come across a problem I don't understand how to fix. I can handle most instances when it's in regular US...
6
by: Michael R | last post by:
I haven't found anything that would help me to understand the correct syntax for having a certain number of digits phone number validation rule. My input mask for this field is: \000\-0000000;;...
2
by: ajaymohank | last post by:
Hello friends............ i am trying to get a validation for email and phone number. in my php project i am doing the validation using java script. but i am not getting validations for email and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.