public void AlphaNumericString() { //string value; string s = BacBox.Text.ToString(); int.TryParse(s, out int result); Regex r = new Regex("^[a-zA-Z0-9]*$"); if (r.IsMatch(s) && (s.Length > 3 && s.Length< 5 )) { BacBox.Text = s; } else { MessageBox.Show("Enter 4 alphanumeric characters only"); } }
^[a-zA-Z0-9]{4}$
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)