Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim s As String
s = Text1.Text
Dim i As Long
i = Len(s)
If i >= Len("####.##.##") Then
KeyAscii = 0
Exit Sub
Else
If KeyAscii <> 8 Then '如果按下的不是退格键
Select Case i
Case 0
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
Exit Sub
End If
Case 1
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
Exit Sub
End If
Case 2
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
Exit Sub
End If
Case 3
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
Exit Sub
End If
Case 4
If KeyAscii <> 46 Then
KeyAscii = 0
Exit Sub
End If
Case 5
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
Exit Sub
End If
Case 6
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
Exit Sub
End If
Case 7
If KeyAscii <> 46 Then
KeyAscii = 0
Exit Sub
End If
Case 8
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
Exit Sub
End If
Case 9
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
Exit Sub
End If
End Select
End If
End If
End Sub