Solved

Regex - check for order numbers starting with alpha numeric

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

730 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