Reputation: 51
The only numbers in the username have to be at the end. There can be zero or more of them at the end.
Username letters can be lowercase and uppercase.
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
Upvotes: 4
Views: 4507
Reputation: 545
This is my answer, it passed all the tests:
/^[a-z][a-z]+\d*$|^[a-z]\d{2,}$/i
Upvotes: 0
Reputation: 1
Simplified version of /^[a-z]{2,}\d*$|(?=\w{3,})^[a-z]{1,}\d+$/i
:
/^\D(\d{2,}|\D+)\d*$/i
Code explanation:
^
- start of input\D
- first character is a letter\d{2,}
- ends with two or more numbers|
- or\D+
- has one or more letters next\d*
- and ends with zero or more numbers$
- end of inputi
- ignore case of inputUpvotes: 0
Reputation: 23
You've missed cases when there's a letter in the start, followed by 2 or more numbers.
U99 = fail
d345 = fail
My solution passes these tests, as well:
/^[a-z]{2,}\d*$|(?=\w{3,})^[a-z]{1,}\d+$/i
Using positive lookahead I am making sure that in the second case there are at least 3 alphanumeric characters.
Upvotes: 0
Reputation: 139
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
Upvotes: 2
Reputation: 3030
/^[A-z]{2,}[A-z0-9]{0,}$/
/^ // start of line
[A-z]{2,} //alphabet characters 2 or more
[A-z0-9]{0,} //numbers and alphabet
$/ // end of line
Upvotes: 0
Reputation: 31712
/^[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)
Upvotes: 4