I want to validate usernames according to this schema:
This regular expression satisfies 1 and 2 above, but I can't figure out how to satisfy 3:
/^[a-zA-Z\d][\w\-]+$/
(I'm using Ruby, if that's relevant)
Not very efficient, but simple:
/^(?!\d+$)[a-zA-Z\d][\w\-]+$/
The lookahead simply means: "what follows isn't a string of numbers that go on until the end".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With