bycj.net
当前位置:首页 >> vB文本框只允许输入数字 >>

vB文本框只允许输入数字

使用正规表达式 以js脚本为例:this.value=this.value.replace(/[^0-9]\D*$/,"")

选择其它对象时,文本框将失去焦点,因此可以用LostFocus事件来执行你要的操作:Private Sub Text1_LostFocus() if len(text1.text)18 then msgbox "必须是18位!" end if if isnumeric(text1.text)=false then msgbox "只能输入数字!" end if End Sub

Private Sub Form_Load()Text1.MaxLength = 11End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)aa = "1234567890"If KeyAscii = 8 Then Exit SubIf InStr(aa, Chr(KeyAscii)) = 0 Then KeyAscii = 0End SubPrivate Sub Text1_LostFocus()

你好!Private Sub Command1_Click()Dim 值 As SingleIf Len(Text1) 6 ThenMsgBox "你输入的位数不对啊"Exit SubEnd If值 = Val(Text1)If 值 >= 1000 Or 值 评论0 0 0

'设置Text1文本最大长度为4Private Sub Form_Load() Text1.MaxLength = 4 Text1 = ""End Sub'屏蔽掉除数字键,Backspace和Delete之外的按键,同时屏蔽Ctrl + V粘贴Private Sub Text1_KeyPress(KeyAscii As Integer) Select Case KeyAscii

建立好程序后,运行,把鼠标放在文本框中,直接在键盘上按数字就可以了,比如按25,就在文本框里出现了25.

用NumericUpDown 或者MaskedTextBox设置Mask = 9999.99

If Len(Text1.Text) <> 2 Then a = TrueIf Val(Text1.Text) > 31 Or Val(Text1.Text) < 1 Then a = TrueIf a = True ThenMsgBox ""Text1.Text = "01"End If将上面的代码插入到检测文本的地方插入

添加以下事件即可.privatesubtext1_keypress(keyasciiasinteger) ifkeyascii<48orkeyascii>57thenkeyascii=0 endsub

只能用笨办法.Private Sub Command1_Click()Dim size as IntegerDim ch as Stringsize=len(Text1.Text)if size<>10 thenmsgbox "请输入10位数字"end ifFor i=0 to sizech=mid(text1.text,i,1)if ch="0" or ch="1" or ch="2" or ch="3"

网站首页 | 网站地图
All rights reserved Powered by www.bycj.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com