Original: implementation: A text box in a C # form can only enter Chinese characters, and the other input is not valid. Q: How is regular expression used?
private void Textbox1_keypress (object sender, KeyPressEventArgs e)
? ? ? ? {
? ? ? ? ? ? Regex RG = new Regex ("^[\u4e00-\u9fa5]$");
? ? ? ? ? ? if (!RG. IsMatch (E.keychar.tostring ()) && e.keychar! = ' \b ')//' \b ' is the backspace key
? ? ? ? ? ? {
? ? ? ? ? ? ? ? E.handled = true;
? ? ? ? ? ? }
? ? ? ? }
Or
private void Textbox1_keypress (object sender, KeyPressEventArgs e)
? ? ? ? {
? ? ? ? ? ? Regex RG = new Regex ("^[\u4e00-\u9fa5\b]$"); \b is the backspace key
???? if (!rg. IsMatch (E.keychar.tostring ()))
? ? ? ? ? ? {
? ? ? ? ? ? ? ? E.handled = true;
? ? ? ? ? ? }
? ? ? ? }
text box can only input Chinese characters, letters, numbers, symbols, spaces typed invalid, backspace can be used, fully realized. Thank you so much!
Transferred from: http://zhidao.baidu.com/question/421426815.html
Implementation: A text box in a C # form can only enter Chinese characters, and the other input is not valid. Q: How is regular expression used?