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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do check a string format?

Status
Not open for further replies.

ceyhorn

Programmer
Nov 20, 2003
93
0
0
US
I'm trying to check to make sure the text box has a number in the format of: #####-##, or five digits a dash and then two digits. How would i do this.

Thanks in advance,
Chris
 
You can use a Regular expression:

Code:
Imports System.Test.RegularExpressions

Dim myRegExp as New RegEx("\d{5}-\d{2}")
if myRefExp.IsMatch(txtMe.Text) then
'** Is good
else
'** Is NOT good
End If
 
Thanks Beck, but the expression is always failing even with the correct format. Any ideas?

Thanks again,
Chris
 
I just coped & tested, besides a few typos it worked for me.
Her's the "spell checked" code:

Code:
Imports System.Text.RegularExpressions
        Dim myRegExp As New Regex("\d{5}-\d{2}")
        If myRegExp.IsMatch(Me.txtRecordLength.Text) Then
            MsgBox("PASSED")
            '** Is good
        Else
            '** Is NOT good
            MsgBox("FAILED")
        End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top