c# - Check if a string contains a character ignoring case -


i have textbox on gui takes "mobile number" input. want validate find out if has characters, mean number invalid

so, number 9876543210 valid while number 98765df013 invalid

i made array of characters (which not allowed me)

string[] alphabeticchars       = new string[] {                                                                         "a", "b", "c", "d", "e", "f", "g",                                                                     "h", "i", "j", "k", "l", "m", "n",                                                                     "o", "p", "q", "r", "s", "t", "u",                                                                     "v", "w", "x", "y", "z"                                                                }; 

and wrote validation function

public bool hascharacters(string text) {     foreach(string character in this.alphabeticchars)          if(text.contains(character.tolower()) || text.contains(character.toupper()))                  return true;      return false; } 

as can see, need call contains twice, 1 "lower case" , time "upper case". checked , couldn't find containsignorecase or something.

what best way to such thing ? (don't mention regular expressions, don't want use them)

in simple way :-)

foreach(string character in this.alphabeticchars)      if(text.tolower().contains(character))              return true; 

or maybe can regular expression more efficient


Comments