Results 1 to 5 of 5

Thread: string validation

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2002
    Location
    London
    Posts
    678

    string validation

    I would like to make sure the entered value in a text box on the windows form is as follows:
    1)it must be seven characters long
    2) it must comprise of the first character being a letter
    3)and the following six characters being numerical digits.

    Thanks

  2. #2
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: string validation

    have you looked at using regular expressions. You could also use a validation control to assist this. See what you can find Im sure its the way to go.

  3. #3
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: string validation

    Something like this?
    Is a reg ex
    VB Code:
    1. [a-zA-Z]\w{1}\d{6}

  4. #4
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: string validation

    Look although the reg ex doesnt work how it should this demonstrates me using the imports system.text.regularexpressions namespace then employing it in the validating event of my textbox control.
    From here its just a case of getting the right regex.
    VB Code:
    1. Private Sub txtCallNotes_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtCallNotes.Validating
    2.         Dim expr As New Regex("\d{6}")
    3.         If expr.ismatch(Me.txtCallNotes.Text) Then
    4.             MessageBox.Show("OK")
    5.         Else
    6.             MessageBox.Show("Bad")
    7.         End If
    8.     End Sub

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: string validation

    Use the Regex.IsMatch() function with FishGuy's regex string to compare the inputs.

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