|
-
Apr 20th, 2005, 01:48 PM
#1
Thread Starter
Lively Member
simple validation
i want 2 simple textbox validation.
1) a textbox validation on allow 0 to 100 only.
2) a textbox to allow only 50 characters.
please help on coding.
-
Apr 20th, 2005, 01:52 PM
#2
Re: simple validation
 Originally Posted by vivian2u
i want 2 simple textbox validation.
1) a textbox validation on allow 0 to 100 only.
2) a textbox to allow only 50 characters.
please help on coding.
No coding necessary. In design set the maxlength property to the desired length.
Edit: After re-reading your question, I'm not sure about number 1. I don't know if you want it to be a maximum length of 100, or only allow numbers up to 100, so in case it is the latter, I'll add this.
VB Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 46 And KeyAscii <> 13 Then
MsgBox "Only numbers are allowed for this entries"
KeyAscii = 0
Exit Sub
End If
If Val(Text1.Text) > 100 Then
Msgbox "A maximum value of 100 is allowed"
Text1.Text = 100
End If
End Sub
'also, in the change event put this code
'to prevent pasting in non numeric text
Private Sub Text1_Change()
If Not IsNumeric(Text1.Text) Then
MsgBox "Only Numbers Are Allowed"
Text1.Text = ""
Exit Sub
End If
If Val(Text1.Text) > 100 Then
Msgbox "A maximum value of 100 is allowed"
Text1.Text = 100
End If
End Sub
Last edited by Hack; Apr 20th, 2005 at 01:59 PM.
-
Apr 20th, 2005, 02:20 PM
#3
Thread Starter
Lively Member
Re: simple validation
the first one is a textbox only allow numeric from 0 to 100 only.
the second one is a textbox to validate only 50 characters are allow.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|