Solved

Need some Regex Help

Posted on 2016-08-16
3
56 Views
Last Modified: 2016-08-16
I need help generating a Regex to test the following (I admit I am no good at this):
Up to 5 digits, and an optional 6th Alpha Only character.  So the pattern would be:
0
01
012
0123
01234
01234A

I started with /^\d{1,5}[a-zA-Z]?/ but this allows a letter in the middle, not just as the 6th character.
This will be tested using the System.Text.RegularExpressions.Regex .IsMatch method in a C# class as the characters are being typed (think a specialized input mask).

Thanks for any help!
0
Comment
Question by:ericlockshine
[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
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
Dan Craciun earned 500 total points
ID: 41758529
You need an alternation:
^\d{1,4}$|^\d{5}[a-zA-z]?$

Open in new window


HTH,
Dan
0
 

Author Closing Comment

by:ericlockshine
ID: 41758541
Works like a champ!
0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 41758550
Glad I could help.
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

732 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