Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular Expression for last six characters in string 2

Status
Not open for further replies.

clanm

Programmer
Dec 26, 2005
237
US
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"

I am very new to expressions.

Any suggestions are welcome!

Thanks!
 
try this expression:
\d{6}$



Known is handfull, Unknown is worldfull
 
Have a look at for help with regular expressions.

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.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.
 
Thanks vbkris and ca8msm for your posts!

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've got this:

\s\w\s\d{6}$


but this allows " c 999999"

Thanks!
 
put a ^ in front of the expression...

Known is handfull, Unknown is worldfull
 
How can I use a regular expression in a subroutine w/o having to use the RegularExpressionValidator?

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 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!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top