check alphanumeric characters in string in c#

后端 未结 8 1074
轻奢々
轻奢々 2020-12-15 05:04

I have used the following code but it is returning false though it should return true

string check,zipcode;
zipcode=\"10001 New York, NY\";
check=isalpha         


        
8条回答
  •  无人及你
    2020-12-15 05:47

    tring check,zipcode;
    zipcode="10001 New York, NY";
    check=isalphanumeric(zipcode)
    
        public static Boolean isAlphaNumeric(string strToCheck)
                {
                    Regex rg = new Regex("[^a-zA-Z0-9]");
    
                    //if has non AlpahNumeric char, return false, else return true.
                    return rg.IsMatch(strToCheck) == true ? false : true;
                }
    

    this code return always false, because the symbole ^ means that's this string doesn't contains any alphanumeric caractere, you need to delete the this ^

提交回复
热议问题