Regular Expression Ideas

Posted on 2011-05-09
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
    LVL 18

    Expert Comment

    Play with this tool:
    Expresso 3.0
    LVL 74

    Expert Comment

    by:käµfm³d 👽

    Open in new window

    LVL 74

    Assisted Solution

    by:käµfm³d 👽

    Open in new window

    LVL 23

    Accepted Solution

    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

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    This video discusses moving either the default database or any database to a new volume.

    729 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now