Solved

Custom Regular Expression

Posted on 2006-11-09
6
202 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

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!

Question has a verified solution.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
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 …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

739 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