I'm using an autocomplete text box, and I need to write a regular expression that will take the last six characters of the string and make sure they're all numeric....like "123456" or "209333"
Also, whilst regular expressions are very good for more complicated scenario's there is another alternative to your question by using the SubString method of the string to get the last 6 digits and then use Integer.TryParse to test the value.
I should have been more specific. What I need to do is check for a space, then the pipecleaner, then a space, then a value that's b/n 000000 and 999999 on the end of my string. So, it's really 9 characters from the right.
Thanks for the help! I'll go to regexlib.com and register too..what a great resource!
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
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.