Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validating userName using Regex

  1. The only numbers in the username have to be at the end. There can be zero or more of them at the end.

  2. Username letters can be lowercase and uppercase.

  3. Usernames have to be at least two characters long. A two-letter username can only use alphabet letter characters.

I'm trying with this but I'm stalled. /\d+$\w+/gi

like image 309
Lomolo Avatar asked Sep 15 '25 10:09

Lomolo


2 Answers

/^[a-z]{2,}\d*$/i is:

^     : the begining
[a-z] : a character (a to z), you can add as many allowed characters as you want
{2,}  : at least 2 of them
\d*   : 0 or more digits 
$     : the end
i     : ignore case sensetivity (both lowercases and uppercases are allowed)
like image 151
ibrahim mahrir Avatar answered Sep 18 '25 00:09

ibrahim mahrir


Username having characters and digit and min 2 character long

/^[a-zA-Z]{2,}\d*$/i

Test result :

UserNam9 = pass
9username = fail
Userna99 = pass
usernameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee = pass
Us = pass
U = fail
like image 27
Shashank Katiyar Avatar answered Sep 17 '25 23:09

Shashank Katiyar