Last active
January 31, 2024 09:20
-
-
Save maxmarinich/a1c4369788cfdbc34a15a387ec3f357a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const punctuation = /^[~`!@#$%^&*(){}\[\];:"'<,.>?\/\\|_+=-]*$/g; | |
const letters = /^[^0-9~`!@#$%^&*(){}\[\];:"'<,.>?\/\\|_+=-]*$/g; | |
const usernamr = /^(?=.{8,20}$)(?![_.])(?!.*[_.]{2})[a-zA-Z0-9._]+(?<![_.])$/; | |
const replaceFirstTwoAndLastFour = (str, symbol) => { | |
const re = /^(.{2})|(.{4})$/g | |
return str.replace(re, replacer) | |
function replacer(match) { | |
return symbol.repeat(match.length) | |
} | |
} | |
/* | |
https://stackoverflow.com/questions/12018245/regular-expression-to-validate-username | |
^(?=.{8,20}$)(?![_.])(?!.*[_.]{2})[a-zA-Z0-9._]+(?<![_.])$ | |
└─────┬────┘└───┬──┘└─────┬─────┘└─────┬─────┘ └───┬───┘ | |
│ │ │ │ no _ or . at the end | |
│ │ │ │ | |
│ │ │ allowed characters, use \w – for Latin, numbers, underscore (eg usernames); | |
│ │ │ | |
│ │ no __ or _. or ._ or .. inside | |
│ │ | |
│ no _ or . at the beginning | |
│ | |
username is 8-20 characters long | |
**/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment