Solved

Regular Expression for Address field...

Posted on 2006-07-10
6
785 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

740 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