如何在textbox里设置第一个字符只能是字母,其他的是数字。
vb.net吧
全部回复
仅看楼主
level 11
叹息行者 楼主
2014年05月13日 15点05分 1
level 11
叹息行者 楼主
就是在textbox里面输入一串字符,第一个只能是字母,之后的必须是数字。就像过滤数据一样!怎样设置,求大神!
2014年05月13日 15点05分 2
level 1
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If TextBox1.Text.Length <= 0 Then '判断字符长度小于1个限制只能输入字母,大于1个限制只能输入数字
If ((e.KeyChar >= "A") And (e.KeyChar <= "Z")) Or ((e.KeyChar >= "a") And (e.KeyChar <= "z")) Then
e.Handled = False '输入有效
Else
e.Handled = True '输入无效
MsgBox("第一个只能输入字母")
End If
Else
If Char.IsDigit(e.KeyChar) Or e.KeyChar = Chr(8) Then
e.Handled = False '输入有效
Else
e.Handled = True '输入无效
MsgBox("只能输入数字")
End If
End If
End Sub
2014年05月21日 08点05分 3
level 1
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If TextBox1.Text.Length <= 0 Then '判断字符长度小于1个限制只能输入字母,大于1个限制只能输入数字
If ((e.KeyChar >= "A") And (e.KeyChar <= "Z")) Or ((e.KeyChar >= "a") And (e.KeyChar <= "z")) Then
e.Handled = False '输入有效
Else
e.Handled = True '输入无效
MsgBox("第一个只能输入字母")
End If
Else
If Char.IsDigit(e.KeyChar) Or e.KeyChar = Chr(8) Then
e.Handled = False '输入有效
Else
e.Handled = True '输入无效
MsgBox("只能输入数字")
End If
End If
End Sub
2014年05月21日 08点05分 4
level 12
不好,楼上无法抵御复制粘贴呀
用textchange吧
2014年05月22日 04点05分 5
level 8
你可以看下我的改下
2014年05月24日 15点05分 6
1