Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
How to validate UserName that should start with characters followed by underscore and then followed by characters??


Thanks...
Posted
Updated 23-Sep-12 19:53pm
v2
Comments
D-Kishore 24-Sep-12 1:55am    
Kindly give me one example(output)

try this

C#
public bool IsAlphaNumericWithUnderscore(string input)
{
    return Regex.IsMatch(input, "^[a-zA-Z0-9_]+$");
}



or
C#
bool result = input.All(c=>Char.IsLetterOrDigit(c) || c=='_');
 
Share this answer
 
v3
You can use the regular expression for this. something like this.
C#
var regExp = new Regex("[a-zA-Z]+_[a-zA-Z]+");
Match match = regExp.Match(UserName);
if (!match.Success)
{
  //Invalidate.
  //return
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900