You are viewing a single comment's thread from:

RE: The 5 Rules of a Valid Username on the Steem Blockchain (and a 3 SBD contest to make an account name validation RegEx)

in #programming8 years ago (edited)

Oh!

Then we're only missing the alternating hyphen and it's done.

^[a-z](-[a-z0-9])?([a-z0-9]-[a-z0-9]|[a-z0-9])*([a-z0-9]-)?[a-z0-9](?:\.[a-z](-[a-z0-9])?([a-z0-9]-[a-z0-9]|[a-z0-9])*([a-z0-9]-)?[a-z0-9])*$

More tests:

Sort:  

How about

. (-.(-.)*)? (.-.|.)* ((.-)*.-)? .

Alternating hyphens wouldn't work either

Further testing:

How about

. (-.(-.)*)? (.-.|.)*

Over eager in matching that last character. I should actually put your test cases into a tester before throwing this out there haha... I'll do that next time I swear.

I did it! You weren't far! You just had to delete the first character acceptance in your last .-., since the previous section already ended in letter/number.

^[a-z](-[a-z0-9](-[a-z0-9])*)?(-[a-z0-9]|[a-z0-9])*(?:\.[a-z](-[a-z0-9](-[a-z0-9])*)?(-[a-z0-9]|[a-z0-9])*)*$

Now wondering if it's possible to add a maximum number of characters in this regex.

Working the same way as before.

^[a-z](-[a-z0-9](-[a-z0-9])*)?([a-z0-9]-[a-z0-9]|[a-z0-9])*(?:[a-z](-[a-z0-9](-[a-z0-9])*)?([a-z0-9]-[a-z0-9]|[a-z0-9])*)$

My bad, it actually works better

^[a-z](-[a-z0-9](-[a-z0-9])*)?([a-z0-9]-[a-z0-9]|[a-z0-9])*(?:[a-z](-[a-z0-9](-[a-z0-9])*)?([a-z0-9]-[a-z0-9]|[a-z0-9])*)*$

It's actually working pretty well. I had just missed a period.

but it's still missing a test case.

Further testing:

And more tests:

& more