Skip to content

Instantly share code, notes, and snippets.

@reduardo7
Created October 8, 2018 19:10
Show Gist options
  • Save reduardo7/9fb6aabaa79de72ead4e435374ee6a10 to your computer and use it in GitHub Desktop.
Save reduardo7/9fb6aabaa79de72ead4e435374ee6a10 to your computer and use it in GitHub Desktop.
UserName validation
function testUser(t) {
console.info(t,
/^[a-z0-9\.\-_]+$/.test(t) && /^[^\.\-_]+/.test(t) && /[^\.\-_]+$/.test(t) && !/[\.\-_]{2,}/.test(t),
/^[a-z0-9\.\-_]+$/.test(t) , /^[^\.\-_]+/.test(t) , /[^\.\-_]+$/.test(t) , !/[\.\-_]{2,}/.test(t));
}
// Valid
testUser('foo');
testUser('foo.bar');
testUser('foo.bar-asd_123');
// Invalid
testUser('foo.-bar');
testUser('foo.');
testUser('-foo');
testUser('-foo.');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment