Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
i am working on a project where i need to make validation to allow only letters and spaces
anything except that should return false.. how can i do this ?
i have my working code
C#
bool usernamecheckchar = txboxName.Text.Any(x => !char.IsLetter(x));
            if (usernamecheckchar == true)
            {
                //entered text may contain spaces and characters only
                bool usernamecheckspaces = txboxName.Text.Contains(" ");
                if (usernamecheckspaces == true)
                {

                }
                else
                {

                }
            }
            else
            {

            }
Posted
Comments
Arkadeep De 30-Jun-15 3:33am    
whats the problem here???? are you getting any error??

1 solution

Use a regex:
C#
if (!Regex.Match(txboxName.Text, @"[^\sa-zA-Z]").Success)
   {
   // Spaces and alphabetics only
   ...
   }
 
Share this answer
 

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