Solved

Custom Regular Expression

Posted on 2006-11-09
6
203 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
[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
  • 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 500 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
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!

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

630 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