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.
Printable View
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.Quote:
Originally Posted by vivian2u
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
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.