Search code examples
c#charalphabet

How to check if a char is in the alphabet in C#


I think the title says enough.

void onClickSubmit(char submit)
{
     if(submit.//check if it is alphabetical)
     {
           //some code
     }
}

how can i check if the char submit is in the alphabet?


Solution

  • You can use regex if your alphabet are only A-Z or a-z

    char a = 'A';
    bool isAlphaBet = Regex.IsMatch(a.ToString(), "[a-z]", RegexOptions.IgnoreCase);
    if(isAlphaBet )
    {
        //do this..
    }