Solved

Need some Regex Help

Posted on 2016-08-16
3
35 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 34

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 34

Expert Comment

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
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…

758 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

22 Experts available now in Live!

Get 1:1 Help Now