[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Need some Regex Help

Posted on 2016-08-16
3
Medium Priority
?
73 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
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
Dan Craciun earned 2000 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

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
We are witnesses that everyone is saying that our children shouldn't "play" with a technology because it is dangerous. This article is going to prove that they are wrong.
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…
Suggested Courses
Course of the Month20 days, 8 hours left to enroll

867 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