Skip to content

Instantly share code, notes, and snippets.

@maxmarinich
Last active January 31, 2024 09:20
Show Gist options
  • Save maxmarinich/a1c4369788cfdbc34a15a387ec3f357a to your computer and use it in GitHub Desktop.
Save maxmarinich/a1c4369788cfdbc34a15a387ec3f357a to your computer and use it in GitHub Desktop.
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