Regular Expression Ideas

Posted on 2011-05-09
Medium Priority
Last Modified: 2013-12-16
I need to validate input into a textblock, and I'm I'm think a regular expression might be suitable.

The criteria is as follows:

numeric . (AV or AI or SCH)numeric

e.g. 1234.AV4321 or 18327.AI1928 or 10293.SCH1928

The first digit of the numeric parts can not be a zero. 01929.AV01929 is not a valid input.

Any ideas?
Question by:wint100
  • 2
LVL 18

Expert Comment

ID: 35723334
Play with this tool:
Expresso 3.0
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35723339

Open in new window

LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 1000 total points
ID: 35723358

Open in new window

LVL 23

Accepted Solution

wdosanjos earned 1000 total points
ID: 35723366
The Regex to validate that pattern is as follows:

var pattern = new Regex(@"^[1-9]\d*\.((AV)|(AI)|(SCH))[1-9]\d*$");

Here is a sample test:

var pattern = new Regex(@"^[1-9]\d*\.((AV)|(AI)|(SCH))[1-9]\d*$");
var values = new string[]{"1234.AV4321","18327.AI1928","10293.SCH1928","01929.AV01929","1929.AV01929","01929.AV1929"};

foreach (var value in values)
	Console.WriteLine("{0} = {1}", value, pattern.IsMatch(value));

Open in new window


1234.AV4321 = True
18327.AI1928 = True
10293.SCH1928 = True
01929.AV01929 = False
1929.AV01929 = False
01929.AV1929 = False

Open in new window

I hope this helps.

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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 anti-spam), the admin…
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month16 days, 23 hours left to enroll

862 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