Solved

Regex - check for order numbers starting with alpha numeric

Posted on 2011-09-28
4
279 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
  • 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

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…
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.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

813 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

12 Experts available now in Live!

Get 1:1 Help Now