Using Rejex to validate user name
-
hello , i would like to use Rejex to validate a user name. my user name rules are as follows: 1. first character is a letter : a-z, A-Z 2. other characters can be letters , numbers and _ 3. a space can be used only once. i tried this one but it didnt work :
Boolean Result = false;
string PatternString = @"[_-zA-Z0-9\s]$";
Result = Regex.Match(UserNameString, PatternString).Success;tnx in advance, avi
-
hello , i would like to use Rejex to validate a user name. my user name rules are as follows: 1. first character is a letter : a-z, A-Z 2. other characters can be letters , numbers and _ 3. a space can be used only once. i tried this one but it didnt work :
Boolean Result = false;
string PatternString = @"[_-zA-Z0-9\s]$";
Result = Regex.Match(UserNameString, PatternString).Success;tnx in advance, avi
-
im not 100% but try... "[a-zA-z][a-zA-z0-9_]*[ ]?[a-zA-Z0-9_]$"
Life goes very fast. Tomorrow, today is already yesterday.
-
hi, its semi working. there is a problem with the initial value. i can enter the following string: ,jukj and it will also be successfull. tnx, avi
-
hello , i would like to use Rejex to validate a user name. my user name rules are as follows: 1. first character is a letter : a-z, A-Z 2. other characters can be letters , numbers and _ 3. a space can be used only once. i tried this one but it didnt work :
Boolean Result = false;
string PatternString = @"[_-zA-Z0-9\s]$";
Result = Regex.Match(UserNameString, PatternString).Success;tnx in advance, avi
shabya wrote:
1. first character is a letter : a-z, A-Z 2. other characters can be letters , numbers and _ 3. a space can be used only once.
Based on that, I suggest a little modification to musefan's regex.
"^[a-zA-z][a-zA-z0-9_]*\s?[a-zA-Z0-9_]*$"
Eslam Afifi
-
oh yes, you need to make it specify to use the start of the string, i think ^ does that job... "^[a-zA-z][a-zA-z0-9_]*[ ]?[a-zA-Z0-9_]$"
Life goes very fast. Tomorrow, today is already yesterday.
You also probably need another asterisk in there right before the $. Otherwise it'll only allow one more character after the optional space.
-
You also probably need another asterisk in there right before the $. Otherwise it'll only allow one more character after the optional space.
-
shabya wrote:
1. first character is a letter : a-z, A-Z 2. other characters can be letters , numbers and _ 3. a space can be used only once.
Based on that, I suggest a little modification to musefan's regex.
"^[a-zA-z][a-zA-z0-9_]*\s?[a-zA-Z0-9_]*$"
Eslam Afifi
-
oh yes, you need to make it specify to use the start of the string, i think ^ does that job... "^[a-zA-z][a-zA-z0-9_]*[ ]?[a-zA-Z0-9_]$"
Life goes very fast. Tomorrow, today is already yesterday.