如何判斷文本框中輸入是否是數字?
如何判斷文本框中輸入是否是number? 问题点数:0、回复次数:7Top
1 楼icefirelxb(icefire)回复于 2003-11-01 15:12:54 得分 0
比如說number(6,4)Top
2 楼wwonion(洋葱)回复于 2003-11-01 15:33:49 得分 0
用
egularExpressionValidator
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator id="RegularExpressionValidator1" runat="server" ErrorMessage="你只能输入数字" ControlToValidate="TextBox1" ValidationExpression="^[0-9]+$"></asp:RegularExpressionValidator>Top
3 楼icefirelxb(icefire)回复于 2003-11-01 15:48:39 得分 0
注意,裡面有小數點Top
4 楼xvting(xvting)回复于 2003-11-01 16:32:55 得分 0
学习Top
5 楼icefirelxb(icefire)回复于 2003-11-01 16:56:53 得分 0
哪位大人榜幫忙Top
6 楼icefirelxb(icefire)回复于 2003-11-01 17:46:09 得分 0
用RegularExpressionValidator1系統提示沒有安裝,還是什麼意思。怎麼辦?我想自己寫函數?但是怎麼把字符串的字符一個個讀出來?Top
7 楼Dugu_Niu(Zealot.name)回复于 2003-11-01 18:27:31 得分 0
最好做一个用户控件,以便以后重复使用,
从TextBox继承
在KeyPress事件中写以下代码:
Dim KeyAscii As Integer
KeyAscii = Asc(e.KeyChar)
Select Case KeyAscii
Case 48 To 57, 8, 13 ' these are the digits 0-9, backspace,
' and carriage return
' we're OK on these, don't do anything
Case 45 ' minus sign
' if we already have one, throw it away
If InStr(Me.Text, "-") <> 0 Then
KeyAscii = 0
Exit Sub
End If
' if the insertion point is not sitting at zero
' (which is beginning of field), throw away the minus
' sign (because it's not valid except in first position)
If Me.SelectionStart <> 0 Then
KeyAscii = 0
End If
Case 46 ' this is a period (decimal point)
' if we already have a period, throw it away
If InStr(Me.Text, ".") <> 0 Then
KeyAscii = 0
End If
Case Else
' provide no handling for the other keys
KeyAscii = 0
End Select
' If we want to throw the keystroke away, then set the event
' as already handled. Otherwise, let the keystroke be handled normally.
If KeyAscii = 0 Then
e.Handled = True
Else
e.Handled = False
End If
做好之后编译生成dll文件,然后在你的项目中引用这个dll就可以
Top




