Solved

Regular Expression for Address field...

Posted on 2006-07-10
6
773 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

9 Experts available now in Live!

Get 1:1 Help Now