?
Solved

Regular Expression for Address field...

Posted on 2006-07-10
6
Medium Priority
?
789 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
Industry Leaders: 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 2000 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

771 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