3 Replies - 220 Views - Last Post: 08 February 2012 - 06:59 AM Rate Topic: -----

Topic Sponsor:

#1 Jerrrum  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 08-February 12

Validate individual characters in textbox

Posted 08 February 2012 - 06:23 AM

Hello there, i am trying to validate a string that has been inputted into a text box so that it checks all of the characters in the text box individually. I have got the code to check the first character...

If Char.IsLetter(textbox1.Text) = False Then
            MsgBox("Error! Invalide charecters present")
            Exit Sub
        End If If


I was just wondering if there is some sort of loop that i can do so that it checks all of the characters in the text box. Any help appreciated! Thanks.

Sorry the piece of the code in the center should be...

If Char.IsLetter(txtCustomerName.Text) = False Then
            MsgBox("Error! Invalide charecters present in customers name")
            Exit Sub
      End If

This post has been edited by smohd: 08 February 2012 - 06:23 AM
Reason for edit:: fixed code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Validate individual characters in textbox

#2 smohd  Icon User is offline

  • Critical Section
  • member icon



Reputation: 1644
  • View blog
  • Posts: 4,126
  • Joined: 14-March 10

Re: Validate individual characters in textbox

Posted 08 February 2012 - 06:26 AM

Ya sure, you can loop in every character by remembering that string is an array of characters. So loop through the string of word as an array of characters and you can deal with every character in it.
Or you ca validate them while entered.

This post has been edited by smohd: 08 February 2012 - 06:31 AM

Was This Post Helpful? 1
  • +
  • -

#3 Jerrrum  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 08-February 12

Re: Validate individual characters in textbox

Posted 08 February 2012 - 06:48 AM

Thanks! It might be a stupid question but what does the e.handled = true do/mean?

        '97 - 122 = Ascii codes for simple letters
        '65 - 90  = Ascii codes for capital letters
        '48 - 57  = Ascii codes for numbers

        If Asc(e.KeyChar) <> 8 Then
            If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then
                e.Handled = True
                MsgBox("Error! Invalid charecter entered")
            End If
        End If

Was This Post Helpful? 0
  • +
  • -

#4 trevster344  Icon User is offline

  • Slick.
  • member icon

Reputation: 124
  • View blog
  • Posts: 873
  • Joined: 16-March 11

Re: Validate individual characters in textbox

Posted 08 February 2012 - 06:59 AM

If I'm not mistaken it tells the computer that you've handled the event of that particular key press yourself, and don't need any assistance from the default control handler. False the compiler will take care of that for you, True you handle the event yourself.

Handled Property

This post has been edited by trevster344: 08 February 2012 - 07:00 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1