So I am HORRIBLE with RegEx... can you help me with the following?
- only allows 52 total characters
- only has "a-z", "A-Z", "0-9", & "-" (letters, numbers, and dashes)
- does not start with "-" (dash)
- does not end with "-" (dash)
- does not have "--" (two consecutive dashes together)
- does not have more than 2 "-" (dashes) in the entire string (this is what I'm having problems with)
So here is a helpful list (I guess):
Pass:
abc-123
abc-123-abc
Fail:
-abc-123 (fails due to starting with a dash)
abc-123- (fails due to ending with a dash)
abc-123-abc-123 (fails due to 3 dashes)
abc-12#-abc (failed due to having a character that is not a-z, A-Z, 0-9, or a dash)
This is what I currently have, but feel free to change it however you would like:
(?!.*--)^[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,50}[a-zA-Z0-9])?$
I'm sure there's a better way to do this, but as mentioned above, I'm horrible with expressions. My expression works, it just doesn't find more than two dashes.
Thanks for your help.