Solved

Regular Expression for Address field...

Posted on 2006-07-10
6
787 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

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…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

695 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