I making a simple chat application, and I need to write a claas that creates user nickname.
for example: NickName nm = NewNickname (“john123”);
So, If the name is wrong (unacceptable) it should throw an exception.
Limiations:
– minimum 4 chars
– maximum 12 char (simple Length check)
– only letter and digits
– must start from letter
Now my conception is just use for loop and check every char for letter/digit etc.
But I ask, is any simple Regex (?) method to achieve this? I have no time to learn
all these regex tricks, because i have limited time (and it looks very complicated) 😛
Regular Expression: “^[a-zA-Z][a-zA-Z0-9]{3,11}$”
So start with a letter (lowercase or uppercase) [a-zA-Z], then between 3 and 11 letters or numbers, so [a-zA-Z0-9]{3,11}. ^ means beginning of string, $ means end of string.