hi all,
i want to validate that user name does not contain special character in first letter of string.
how to validate this plz help
hi all,
i want to validate that user name does not contain special character in first letter of string.
how to validate this plz help
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
VulpesRank #55 · 29.2K reputationPosted May 30, 2012, 2:34 AM EDT
http://msdn.microsoft.com/en-us/library/system.char.aspx
If, for example, the first character of the user name needed to be a lower or upper case letter you could test with:
if (!Char.IsLetter(userName[0]))
{
// invalid user name
}
Sumit KumawatRank #4,008 · 372 reputationPosted May 30, 2012, 2:47 AM EDT
this is my code here i want to chk that my input string in tbUsername shuld not contain @"^[a-zA-Z0-9\s.\?\,\'\;\:\!\-]+$" at first place
VulpesRank #55 · 29.2K reputationPosted May 30, 2012, 3:34 AM EDT
Murad BASDAG23 reputationPosted May 30, 2012, 3:57 AM EDT
if (!Char.IsLetter(userName[0]))
{
// invalid user name
}
is a very good and effective way to check is the name starts with a letter. But if you additionaly clear spaces in front of the name can be better.
For example
if (!Char.IsLetter(userName.TrimStart()[0]))
{
// invalid user name
}
Daril148 reputationPosted Nov 22, 2021, 2:43 AM EST
The output will be.
You can also use regex to find the special character