Solved

Regex - check for order numbers starting with alpha numeric

Posted on 2011-09-28
4
283 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 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
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.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

691 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