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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
DarilPosted Nov 22, 2021, 7:43 AM
The output will be.
You can also use regex to find the special character
Murad BASDAGPosted May 30, 2012, 7:57 AM
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
}
VulpesPosted May 30, 2012, 7:34 AM
Sumit KumawatPosted May 30, 2012, 6:47 AM
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
VulpesPosted May 30, 2012, 6:34 AM
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
}