My scenario is:
Not allowing spaces at starting position of textbox after enter one or more characters text box allows spaces
Below not applicable to my sce
you should use the regex
string strRegex = @"^([\w]+.*)$"; string strTargetString = textBox1.Text; if (!Regex.IsMatch(strTargetString, strRegex)) { // show error that spase not allow at the bigin of string }