Test for valid input Leave a reply This regular expression tests the input string for 40 alphanumeric characters Regex r = new Regex(@"^[w]{1,40}$"); if (r.Match(strName).Success) { // The string is ok } else { // Invalid string }