The 5 Rules of a Valid Username on the Steem Blockchain (and a 3 SBD contest to make an account name validation RegEx)
programming·@cryptosharon·
0.000 HBDThe 5 Rules of a Valid Username on the Steem Blockchain (and a 3 SBD contest to make an account name validation RegEx)
<center><img src="https://i.imgur.com/RjlpfJR.png" alt="The rules"></center> The rules for a valid account name in the Steemit blockchain are not as simple as you may think. They have some quirks that I did not know of before I actually read the code that validates each username at account creation in the blockchain. [Here's Steem's code if you want to read it](https://github.com/steemit/steem/blob/1cfdf8101ec415156b155c9ec90b0a4d439a039f/libraries/protocol/authority.cpp) I had to read it a few times, since I don't actually know C++ (the programming language in which the validation code is written), and I will share my findings. <h1>1. Each part around a period (`.`) is a name segment</h1> <center><img src="https://i.imgur.com/M9NGDYl.png" alt="segments"></center> The account name validation does not read the whole name but divides it in segments whose divisions are marked by `.` The following rules will apply mostly to each segment instead of the whole account name. <h1>2. Each segment must be at least 3 characters long</h1> Valid | Invalid --- | --- `cryptosharon`| `cr` `cry.pto`|`sh.ar` <h3>What's the maximum length?</h3> The maximum length of a segment doesn't seem to be defined within the code. However, Steemit enforces a 16 character maximum to the whole account name, and the [test code](https://github.com/steemit/steem/blob/1cfdf8101ec415156b155c9ec90b0a4d439a039f/tests/tests/basic_tests.cpp#L126) seems to assume that the maximum for the blockchain would be 63 or 64 <center><img src="https://i.imgur.com/VUYSuCM.png"><br><img src="https://i.imgur.com/AdbRm6x.png"></center> <h1>3. Each segment must begin with a letter (`a-z`, English alphabet) and end with a letter or a number (`0-9`)</h1> <center><img src="https://i.imgur.com/9BvkvaD.png" alt="begin-end"></center> Valid|Invalid ---|--- `cryptosharon9`|`9cryptosharon` `cry.pto9`|`9sh.aron` `c-r.y-p.t-o9`|`sha.9ron` <h1>4. All letters contained in a segment must be lowercase</h1> Valid|Invalid ---|--- cryptosharon|CryptoSharon <h1>5. Hyphens (`-`) must be accompanied side by side by letters or numbers</h1> <center><img src="https://i.imgur.com/TvAA82D.png" alt="alphanumerical-loners"></center> This means no double hyphens. Hyphens can't be at the beginning or end of a segment either because of rule 3 Valid|Invalid ---|--- `cry-9-pto-5`|`sh--aron` `s-h-a-r-o-n9`|`crptshrn-` `a12.b-3` | `otp-.yrc` <img src="https://i.imgur.com/n0GHXPP.png"> <h3>That's it!</h3> These rules are weird sometimes, and some tidbits are unclear, like the maximum length, but follow them and don't go beyond 16 characters and you'll be ok. <img src="https://i.imgur.com/n0GHXPP.png"> <center><h1>The Contest</h1> <img src="https://i.imgur.com/Su52IWA.png" alt="regex"></center> I wanted to make a RegEx to validate the names, but I couldn't find a way to make sure it didn't grab double hyphens while making the number of hyphens unlimited and optional. Since I really want to have a RegEx for this, I decided to make a contest for it. ### [This is the way Steemit does it](https://github.com/steemit/condenser/blob/918edda1221e379a332ccf84714d0a3136c0bd4f/src/app/utils/ChainValidation.js#L47) <-- (Condenser GitHub repo) It simply iterates the characters and checks with individual regexes, but that's no fun. <h3>I hope a single regex is possible.</h3> If you manage to do it, post it in the comment section. I'll give you 3 SBD :3 And if anyone else wants to give the person more money, that's ok, but I'm poor enough already that this contest seems like crazy money spenditure. The rules for the contest are simple (more rules!): * 1 regex * 1 week * I'll pick the best (if there's any) <img src="https://i.imgur.com/1gtTwu5.png"> <h3>If you're up for the challenge</h3> Don't go alone! Take these resources: * [RegExr](http://regexr.com/) - Test your regexes and learn RegExp the easy way * [RegEx101](https://regex101.com/) - A more in-depth learning tool that also has a tester <img src="https://i.imgur.com/1gtTwu5.png"> <br><center><a href="https://discord.gg/VQyYDnm"><img src="https://i.imgur.com/AUeBnJB.png"></a></center> <center><h4>Other posts that might interest you</h4></center> |<center><a href="https://steemit.com/blog/@cryptosharon/how-the-crisis-has-changed-venezuela-the-rise-of-nepotism">How the Crisis has Changed Venezuela: The Rise of Nepotism</a></center>| |---| |<center><a href="https://steemit.com/music/@cryptosharon/travelling-into-the-world-of-a-song-tar-calion-by-summoning">Travelling into the world of a song: "Tar-Calion" by Summoning</a></center> |<center><a href="https://steemit.com/poetry/@cryptosharon/forlorn-days">Forlorn days</a></center>| |<center><a href="https://steemit.com/writing/@cryptosharon/skye">Skye</a></center>| <center><h3>What did you think of this guide?<br>Do you think the regex is possible?<br><br>Leave me a vote and a comment (and maybe resteem)</h3></center><br> Edit: Best regex so far (by @eonwarped): * `^[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])*)*$`
👍 claudiop63, promosteem, mynaturebody, gtan, walterjay, allasyummyfood, xeldal, alejo0908, ancientsteempunk, eonwarped, postpromoter, amymya, lunaticpandora, minnowbootcamp, maverickinvictus, purepinay, katamori, qrkjadoon, basterundco, fsherberg, orkhan876, mdbrantingham, buildawhale, marekkaminski, jan23com, timurka, thetalkingduck, nomadicsoul, brayias, dawnsheree, teruro, obpamex, big.mama, indranielsen, itinerantartist, eaglespirit, ghasemkiani, jupagoji,