Solved

Regular Expression for Address field...

Posted on 2006-07-10
6
780 Views
Last Modified: 2012-06-21
I know this is simple question, but I am really new to Regular expression...
I need a regular expression to validate my address field, the condns are...
1. Address field must not start with and empty space (also should not be empty)
2. Address field can contain any alpha numeric characters (Only Capital Letters) and any kind of symbols and it should start with one of the Alphanumeric charcters
3. It can contain any number of spaces in between the words (just like a sentence...)
4. It shud not exceed 200 char.

Thank You,
Steve
0
Comment
Question by:steve_mick972
  • 3
  • 2
6 Comments
 
LVL 18

Expert Comment

by:Ravi Singh
ID: 17077614
Hi, try the following regex:

^[A-Z0-9]{1}[^a-z]{1,199}$
0
 
LVL 1

Author Comment

by:steve_mick972
ID: 17077862
That works!!! thanx,
I have one more question...  I have Zip4 field but that field can be either empty or if there is any data it should conform to US Zip4 format (like should not exceed 4 digits etc.,)
Can you please help me out  with that...

Thank You,
Steve
0
 
LVL 10

Expert Comment

by:SystemExpert
ID: 17078963
Hi

Use Numeric validation for ZIP

and use following javascript function 9inside call ValidateNumber [any  numeric validation and i hope you write this]

function ZIPNoValidate()
{
                  
var Result = true;
var lblZIPNo = document.getElementById('lblZIPNo');
var ZIPNo =  document.getElementById('txtZIPNo').value;
//Checking blank
Result = BlankValue(ZIPNo);
if(Result)//Not blank
{
                        
      Result= ValidateNumber(ZIPNo);
      if(Result)//true
      {
            //coloring
            lblZIPNo.className = "fields";
            Result= true;
      }
      else//false
      {
            //coloring
            lblZIPNo.className = "error";
            Result = false;
      }
}
else//blank
{
      //coloring
      lblZIPNo.className = "error";
      Result = false;
}
return  Result;
}

thanks
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 18

Expert Comment

by:Ravi Singh
ID: 17080057
Hi, can you give example Zip4 codes? I don't live in the US and can't find anything concrete regarding their format.
0
 
LVL 1

Author Comment

by:steve_mick972
ID: 17083329
US Zip4 codes should be only 4 digits which should be in 0-9 range...
the problem is, I can write simple Reg.Expr to achieve this... but my data is like that, it can have empty data in that field or it contain zip4 number, I have to validate the field such that it should accept the empty field and if there is anything in that field it should be valid zip4 number...

Some examples for US zip4s are: 2569, 0128, 0065, 7894

I hope you understand my problem...

Thank You,
Steve
0
 
LVL 18

Accepted Solution

by:
Ravi Singh earned 500 total points
ID: 17083719
Hi Steve, try the following to validate the zip code

^[0-9]{4}|\s*$

The zip code can either be 4 numeric digits or zero or more empty spaces.

You can either use the above regex or first test to see if the string is empty by using javascript (or whatever) and if it isnt, you can use the simple regex "^[0-9]{4}$" to check if its a valid zip code. Also, it might be a good idea to trim the input string in case the user inputs strings such as "   8871", if that happens and you use the above regex then it'll only match the preceding empty space and not the zip code.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now