Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Regular Expression in code behind subroutine?

Regular Expression in code behind subroutine?

Scheduled Pinned Locked Moved ASP.NET
databaseregexquestionannouncement
8 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bubberz
    wrote on last edited by
    #1

    Hello! I'm using an autosuggestion text box, and the user can either use blank (string.empty) or a value they got from the ddl for the UPDATE sql. What I'd like to do is make sure if they did select from the ddl, they used the values from the db, and not their own. A correct value would be: Smith Jonathan R | 88899 .....the flow is last name, first name, MI, space, pipecleaner, space, then a six digit character. I know I can use the following as an expression: \s\w\s\d{6}$ ....but I'd also like to do a couple more checks in my subroutine as well. What I'm having trouble is with actually writing the VB in the subroutine for the expression. Everything uses the RegularExpressionValidator that I've gotten back from Google. Thanks!

    B 1 Reply Last reply
    0
    • B bubberz

      Hello! I'm using an autosuggestion text box, and the user can either use blank (string.empty) or a value they got from the ddl for the UPDATE sql. What I'd like to do is make sure if they did select from the ddl, they used the values from the db, and not their own. A correct value would be: Smith Jonathan R | 88899 .....the flow is last name, first name, MI, space, pipecleaner, space, then a six digit character. I know I can use the following as an expression: \s\w\s\d{6}$ ....but I'd also like to do a couple more checks in my subroutine as well. What I'm having trouble is with actually writing the VB in the subroutine for the expression. Everything uses the RegularExpressionValidator that I've gotten back from Google. Thanks!

      B Offline
      B Offline
      bubberz
      wrote on last edited by
      #2

      I'm trying the following in a code behind subroutine, and it's not working. If the value they select is CORRECT, the exeption is still thrown. txtWPMgr.Text should get built from a SQL string the does a select colName+' | '+colNumber It's the colNumber value I want to compare in this expression. Dim regEx As New Regex("^\s\w\s\d{6}$") 'last six characters are digits If Len(Trim(txtWPMgr.Text)) > 0 Then 'Means there are characters for the name If InStr(txtWPMgr.Text, " | ") = 0 Or Not regEx.IsMatch(Trim(txtWPMgr.Text)) Then intDisable = 1 'Mark integer flag lblStatus.Text = "Bad Format!" End If

      B G 2 Replies Last reply
      0
      • B bubberz

        I'm trying the following in a code behind subroutine, and it's not working. If the value they select is CORRECT, the exeption is still thrown. txtWPMgr.Text should get built from a SQL string the does a select colName+' | '+colNumber It's the colNumber value I want to compare in this expression. Dim regEx As New Regex("^\s\w\s\d{6}$") 'last six characters are digits If Len(Trim(txtWPMgr.Text)) > 0 Then 'Means there are characters for the name If InStr(txtWPMgr.Text, " | ") = 0 Or Not regEx.IsMatch(Trim(txtWPMgr.Text)) Then intDisable = 1 'Mark integer flag lblStatus.Text = "Bad Format!" End If

        B Offline
        B Offline
        bubberz
        wrote on last edited by
        #3

        I got it with: 'Start Expression Code Dim regEx As New Regex("\s\|\s\d{6}$") 'last six characters are digits for number If Len(Trim(strNewPerson)) > 0 Then 'Means there are characters for the name If InStr(strNewPerson, " | ") = 0 Or Not regEx.IsMatch(Trim(strNewPerson)) Then lblStatus.Text = "* Name value must be from dropdown list built when typing name(last name first)!" Exit Sub Else lblStatus.Text = String.Empty End If End If 'End Expression code Thanks!

        1 Reply Last reply
        0
        • B bubberz

          I'm trying the following in a code behind subroutine, and it's not working. If the value they select is CORRECT, the exeption is still thrown. txtWPMgr.Text should get built from a SQL string the does a select colName+' | '+colNumber It's the colNumber value I want to compare in this expression. Dim regEx As New Regex("^\s\w\s\d{6}$") 'last six characters are digits If Len(Trim(txtWPMgr.Text)) > 0 Then 'Means there are characters for the name If InStr(txtWPMgr.Text, " | ") = 0 Or Not regEx.IsMatch(Trim(txtWPMgr.Text)) Then intDisable = 1 'Mark integer flag lblStatus.Text = "Bad Format!" End If

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          You have forgotten to specify how many characters of each you allow. Now you are matching a single white-space character, a single alphanumeric character, a single white space character and six digits.

          --- b { font-weight: normal; }

          B 1 Reply Last reply
          0
          • G Guffa

            You have forgotten to specify how many characters of each you allow. Now you are matching a single white-space character, a single alphanumeric character, a single white space character and six digits.

            --- b { font-weight: normal; }

            B Offline
            B Offline
            bubberz
            wrote on last edited by
            #5

            Guffa, That's all I want to allow: a single white-space character, a single alphanumeric character, a single white space character and six digits

            G 1 Reply Last reply
            0
            • B bubberz

              Guffa, That's all I want to allow: a single white-space character, a single alphanumeric character, a single white space character and six digits

              G Offline
              G Offline
              Guffa
              wrote on last edited by
              #6

              I thought that you had a string in the format "Smith Jonathan R | 888999"?

              --- b { font-weight: normal; }

              B 1 Reply Last reply
              0
              • G Guffa

                I thought that you had a string in the format "Smith Jonathan R | 888999"?

                --- b { font-weight: normal; }

                B Offline
                B Offline
                bubberz
                wrote on last edited by
                #7

                Guffa, Thanks for staying with this. Yes, my string is something like: "Bush George W | 987987" ...and I thought this would/should do the trick to make sure the end of my string is correct: Dim regEx As New Regex("\s\|\s\d{6}$") ...am I missing something? What I don't want someone to do is allow users to take "Bush George W | 987987" and make it : "George W Bush" or "Bush George W" or "Bush George W | 987"

                G 1 Reply Last reply
                0
                • B bubberz

                  Guffa, Thanks for staying with this. Yes, my string is something like: "Bush George W | 987987" ...and I thought this would/should do the trick to make sure the end of my string is correct: Dim regEx As New Regex("\s\|\s\d{6}$") ...am I missing something? What I don't want someone to do is allow users to take "Bush George W | 987987" and make it : "George W Bush" or "Bush George W" or "Bush George W | 987"

                  G Offline
                  G Offline
                  Guffa
                  wrote on last edited by
                  #8

                  Yes, in that case that pattern works. It's wasn't that pattern you used in the message I replied to, though.

                  --- b { font-weight: normal; }

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups