Link to home
Start Free TrialLog in
Avatar of gsdevEE
gsdevEEFlag for United States of America

asked on

Regex for 12 alphanumeric characters, a dash "-", and 1 to 12 characters in length, including whitespace

Regex for 12 alphanumeric characters, a dash "-", and 1 to 12 characters in length, including whitespace.


So abc-12345678 would be valid

abc-123456789 would be invalid

And any string including any characters other than these would be invalid.

I cant figure the regex out.  Im sure there is someone who can get this quick, and I have too many bugs on my plate - thanks !

C#
Avatar of elimesika
elimesika
Flag of Israel image

Here it is

[a-zA-Z -]{1,12}

Open in new window

Avatar of Patrick Matthews
Hello gsdevEE,

Would the following be valid:

----
          
1234
abcd

They all meet the written criteria, but look somewhat different from your only example of a valid code...

Regards,

Patrick
elimesika,

I think you meant:

[a-zA-Z0-9 -]{1,12}

:)

Patrick
Hi  gsdevEE;

This regex pattern should do what you want.

Fernando
^[a-zA-Z0-9-]{1,12}$

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial