Solved

Custom Regular Expression

Posted on 2006-11-09
6
200 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 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
ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

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 …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

777 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