Regular Expression in code behind subroutine?
-
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!
-
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!
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
-
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
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!
-
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
-
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; }
-
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
-
I thought that you had a string in the format "Smith Jonathan R | 888999"?
--- b { font-weight: normal; }
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"
-
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"