Krimson
Krimson

Reputation: 7664

Regex: need help to meet 3 criterias

could someone help my build a regex? It is for a username check

the requirements are

  1. Alpha numeric
  2. Any case
  3. On - or a _ allowed from non alpha numeric set

Thanks, Vidhu!

Upvotes: 0

Views: 47

Answers (3)

Connor
Connor

Reputation: 64634

I think this should cover your requirements.

    ([a-zA-Z-_\d]*)

Upvotes: 0

Chris
Chris

Reputation: 440

\w gives you any "word" character (number, letter, underscore of any case) and - is just a dash.

[\w-]*

http://www.rubular.com is a great site to test regular expressions. It has a good reference too.

Upvotes: 3

juan.facorro
juan.facorro

Reputation: 9920

I think the following accomplishes all three:

[A-Za-z0-9\-_]*

Or better still:

[\w\-]*

Upvotes: 2

Related Questions