本文介绍了手机号码文本框验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞!using System.Text.RegularExpressions;Regex re = new Regex("^9[0-9]{9}");if (re.IsMatch(txtMob.Text.Trim()) == false || txtMob.Text.Length > 10){ MessageBox.Show("Invalid Mobile Number !!"); txtMob.Focus();} 我已实施上述代码,并显示任何给定号码的无效手机号码。 我想实现验证,当输入任何字符时会显示不允许字符消息,当超过10位数时显示无效数字消息输入。 请帮帮我!I have implemented the above code and it displays invalid mobile number for any given number.I would like to implement validations, which would show a "Characters are not allowed" message when any characters are typed and show an invalid number message when more than 10 digits are entered.Please help me out!推荐答案private void txy_Keypress(object sender, KeyPressEventArgs e) { if (!char.IsNumber(e.KeyChar) & (Keys)e.KeyChar != Keys.Back & (Keys)e.KeyChar != Keys.Enter) { e.Handled = true; } base.OnKeyPress(e); } 和TextChanged事件写下这段代码:and on TextChanged event write this code :if (txtMob.Text.Length > 10){MessageBox.Show("Invalid Mobile Number !!");txtMob.Focus();} 或设置文字Maxlenth proparty set 10 希望这个帮助or set text Maxlenth proparty set 10hope this help 这篇关于手机号码文本框验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-21 07:04