locked
Checking text within textbox - VB.NET RRS feed

  • Question

  • User-1134314964 posted

    Hello,

    I have a search textbox.  I need the code-behind to check the value of the textbox and act upon it accordingly. I need to differentiate between the different search criteria.

    E.g.
    123 Main - would search by a street address
    Main - would search by owner last name or a street name of Main
    123 - would search by a street number of 123
    09-123456 - would search by parcel number
    10--02-15-00-012-00 - would search by routing number

    I have the number searches working properly (street number, parcel number and routing number).

    If I search for a street address, it sees the whole string as a string instead or it containing a number as well.  I need it to differentiate it between a street address and the owner last name/street name.

    How would I accomplish this?  Thanks.. -Jeff

    strSearchString = txt_SearchFor.Text
    strOriginalTextbox = txt_SearchFor.Text
    strSearchString = Trim(Replace(strSearchString, "-", ""))
    
    If IsNumeric(strSearchString) And Len(strSearchString) = 8 Then
    	lbl_Results.Text = "You used <b>" & strOriginalTextbox & "</b> to search for a parcel number"
    	Exit Sub
    ElseIf IsNumeric(strSearchString) And Len(strSearchString) = 13 Then
    	lbl_Results.Text = "You used <b>" & strOriginalTextbox & "</b> to search for a routing number"
    	Exit Sub
    ElseIf IsNumeric(strSearchString) Then
    	lbl_Results.Text = "You used <b>" & strOriginalTextbox & "</b> to search for a steet number"
    	Exit Sub
    End If
    
    If Not IsNumeric(strSearchString) Then
    	lbl_Results.Text = "You used <b>" & strOriginalTextbox & "</b> to search for a last name or steet name"
    	Exit Sub
    End If
    


     

    Tuesday, March 9, 2010 10:08 AM

Answers

  • User191633014 posted

     You can use Regex:

            If Regex.IsMatch(strSearchString, "^\d+\s[A-Za-z]+$") Then
                'Match for "123 Main"
            ElseIf Regex.IsMatch(strSearchString, "^[A-Za-z]+$") Then
                ' Match for "Main"
            ElseIf Regex.IsMatch(strSearchString, "^\d+$") Then
                ' Match for "123"
            ElseIf Regex.IsMatch(strSearchString, "^\d\d-\d{6}$") Then
                ' Match for "09-123456"
            ElseIf Regex.IsMatch(strSearchString, "^\d\d--\d\d-\d\d-\d\d-\d\d\d-\d\d$") Then
                ' Match for "10--02-15-00-012-00"
            End If


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 9, 2010 11:13 AM

All replies

  • User191633014 posted

     You can use Regex:

            If Regex.IsMatch(strSearchString, "^\d+\s[A-Za-z]+$") Then
                'Match for "123 Main"
            ElseIf Regex.IsMatch(strSearchString, "^[A-Za-z]+$") Then
                ' Match for "Main"
            ElseIf Regex.IsMatch(strSearchString, "^\d+$") Then
                ' Match for "123"
            ElseIf Regex.IsMatch(strSearchString, "^\d\d-\d{6}$") Then
                ' Match for "09-123456"
            ElseIf Regex.IsMatch(strSearchString, "^\d\d--\d\d-\d\d-\d\d-\d\d\d-\d\d$") Then
                ' Match for "10--02-15-00-012-00"
            End If


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 9, 2010 11:13 AM
  • User-1134314964 posted

    Wow, that works great..

    Didn't even know of or think of doing it this way.  Clean and concise.

    Thanks.. -Jeff

     

    Tuesday, March 9, 2010 11:35 AM