Results 1 to 3 of 3

Thread: simple validation

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    81

    Unhappy 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.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: simple validation

    Quote 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:
    1. Private Sub Text1_KeyPress(KeyAscii As Integer)
    2. If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 46 And KeyAscii <> 13 Then
    3.     MsgBox "Only numbers are allowed for this entries"
    4.     KeyAscii = 0
    5.     Exit Sub
    6. End If
    7. If Val(Text1.Text) > 100 Then
    8.     Msgbox "A maximum value of 100 is allowed"
    9.    Text1.Text = 100
    10. End If
    11. End Sub
    12.  
    13. 'also, in the change event put this code
    14. 'to prevent pasting in non numeric text
    15. Private Sub Text1_Change()
    16. If Not IsNumeric(Text1.Text) Then
    17.    MsgBox "Only Numbers Are Allowed"
    18.    Text1.Text = ""
    19.    Exit Sub
    20. End If
    21. If Val(Text1.Text) > 100 Then
    22.     Msgbox "A maximum value of 100 is allowed"
    23.    Text1.Text = 100
    24. End If
    25. End Sub
    Last edited by Hack; Apr 20th, 2005 at 01:59 PM.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    81

    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
  •  



Click Here to Expand Forum to Full Width