请问怎样判别输入框textbox里的数据?
比如我想判定用户输入到textbox里的是否是integer?还是别的?要是integer,又怎样判定是不是0开始的.比如这样的数据无效02002,20y0,h089,j809等,只有201,111等正整数有效. 问题点数:20、回复次数:11Top
1 楼The123(Shall We Dance? :))回复于 2004-09-02 22:14:22 得分 2
http://community.csdn.net/Expert/topic/3256/3256838.xml?temp=.8958551Top
2 楼lwbmail(努力工作...)回复于 2004-09-02 22:17:41 得分 0
验证控件Top
3 楼yuanarea(Sail before)回复于 2004-09-02 22:45:27 得分 0
正则表达式Top
4 楼gaobud(真是搞不懂)回复于 2004-09-02 22:55:19 得分 4
简单的验证写几句代码比较快,也不需要创建其他对象
Dim abc As String
abc = "0123"
If IsNumeric(abc) Then '如果是一个数字
If abc.Substring(0, 1) = "0" Then '如果第一个字符是0
'代码
End If
End IfTop
5 楼zwxrain(Lilo)回复于 2004-09-03 09:54:35 得分 0
indexofTop
6 楼cpz01(一天到晚抽人的烟)回复于 2004-09-03 10:29:11 得分 0
简单的验证写几句代码比较快,也不需要创建其他对象
Dim abc As String
abc = "0123"
If IsNumeric(abc) Then '如果是一个数字
If abc.Substring(0, 1) = "0" Then '如果第一个字符是0
'代码
End If
End If
同意 顶Top
7 楼lcge(沙漠)回复于 2004-09-04 20:36:58 得分 0
请问如何判定它是大于0的数,又如何判断它是正整数即大于0(不含小数)?Top
8 楼IE14571(Leo)回复于 2004-09-04 23:26:50 得分 0
用正则表达式吧,具体请看msdn.Top
9 楼dolfin(梦幻)回复于 2004-09-09 01:23:04 得分 8
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim mystr As String
mystr = TextBox1.Text '需要验效的字符串
If IsNumeric(mystr) And (mystr.IndexOf(".") = -1) Then '如果是一个数字而且不含有小数点(非小数)
If (mystr.Substring(0, 1) <> "0") And (Integer.Parse(mystr) > 0) Then '如果第一个字符不是“”0,而且又大于0的数,则是有效值
'代码
MessageBox.Show("Yes.")
End If
End If
End Sub
Top
10 楼lumj(真奇怪)回复于 2004-09-09 06:52:40 得分 4
楼上的都太麻烦了,用我这个吧
Dim re As New System.Text.RegularExpressions.Regex("^[1-9](\d)*$")
Dim m As System.Text.RegularExpressions.Match = re.Match(Textbox1.Text)
If m.ToString <> Nothing Then
MsgBox("这是个合法的正整数!")
End IfTop
11 楼liujiayu10(活着就好)回复于 2004-09-09 08:13:44 得分 2
Public Function ZZSInt(ByVal TB As TextBox, ByVal PressKey As String) As Boolean '文本框录入带有小数位正>=0数值字段
If Not ((Asc(PressKey) >= 48 And Asc(PressKey) <= 57) OrElse (Asc(PressKey) = 46 And InStr(1, TB.Text, ".") = 0) OrElse Asc(PressKey) = 8) Then
Return True
End If
End FunctionTop




