?
Solved

Regex - check for order numbers starting with alpha numeric

Posted on 2011-09-28
4
Medium Priority
?
285 Views
Last Modified: 2012-05-12
I have order numbers like this : WSUS00016-5 OR WSUS00016

(with and without a dash)

I need a regex to check for both... order numbers that start with alpha and have a dash and those that start with alpha and no dash...

I've tried these : ^a-zA-Z0-9 _]{1,255}
                          ^([A-Za-z]|[0-9]|_)+$
                          /^\w+$/
0
Comment
Question by:Camillia
[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
  • 3
4 Comments
 
LVL 28

Accepted Solution

by:
strickdd earned 2000 total points
ID: 36717772
[A-Za-z]{4}\d{5}(\-[0-9])?
0
 
LVL 10

Expert Comment

by:ienaxxx
ID: 36717782
you missed the number of occurrences.

try this:

^([a-zA-Z\-0-9]*)$
0
 
LVL 10

Expert Comment

by:ienaxxx
ID: 36717808
...or, if you're trying to isolate the numeric part in a separate match:

^([a-zA-Z]*)([0-9\-]*)$

This is because you defined a class of chars and not the number of chars (inside the parentheses)
Doing this will expect to find ONE char of that class.

HTH
Bye.
0
 
LVL 10

Expert Comment

by:ienaxxx
ID: 36717841
* is telling the class can be repeated 0 or more times.
+ would tell (at least one)
{1,3} would tell from one to three

and so on.
but you should specify that near the class definition "[ ]" markers, not outside the match definition "( )" markers.

if you want to match ONLY the order number that are composed by an alpha part of at least 4 chars and a num part of at least 4 that MAY contain a dash, you should search for:

^([a-zA-Z]{4,})([0-9\-]{4,})$

HTH
Bye!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month13 days, 21 hours left to enroll

800 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