Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

Need some Regex Help

Posted on 2016-08-16
3
Medium Priority
?
68 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 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
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

648 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