Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Custom Regular Expression

Posted on 2006-11-09
6
Medium Priority
?
205 Views
Last Modified: 2012-05-05
First of all, is that an oxymoron?

I need a regular expression that is designed to handle a customer's account #. I know the format of the account number but it can change (dashes, spaces, last digit optional) so I'm not sure how to write this expression. I figure somebody who knows this stuff well could write it without too much trouble or at least point me in the right direction. Thanks!

The # is printed on the bill like this:   00-0000000 0    so 2 digits, dash, 7 digits, space, last digit

In the field where they enter their customer #, they may or may not enter the dash after the first two digits and may or may not enter the space before the last digit. I also want to make the last single digit optional all together. Please let me know if I did not explain that well enough. Thanks in advance.
0
Comment
Question by:megel6805
  • 4
6 Comments
 
LVL 16

Expert Comment

by:muzzy2003
ID: 17909566
Try this:

\d{2}-?\d{7} ?\d{0,1}
0
 
LVL 16

Accepted Solution

by:
muzzy2003 earned 2000 total points
ID: 17909575
Sorry - forgot beginning and end:

^\d{2}-?\d{7} ?\d{0,1}$
0
 
LVL 12

Expert Comment

by:sandip132
ID: 17911062
Quantifiers provide a simple way to specify within a pattern how many times a particular character or set of characters is allowed to repeat itself.

*, which describes "0 or more occurrences",
+, which describes "1 or more occurrences", and
?, which describes "0 or 1 occurrence".

To learn to create regular expressions ref. this :
http://msdn2.microsoft.com/en-us/library/ms972966.aspx

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 16

Expert Comment

by:muzzy2003
ID: 17912324
In this case, I have used the quantifiers {n} for exactly n and {n,m} for between n and m. The last one could obviously be written \d? or \d{0,1}.
0
 

Author Comment

by:megel6805
ID: 17934828
thanks!
0
 
LVL 16

Expert Comment

by:muzzy2003
ID: 17936235
No problem.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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…
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…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

926 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