Solved

Help with checking string format? (Windows App VS 2010, with VB.NET)

Posted on 2012-12-27
2
229 Views
Last Modified: 2012-12-27
Hi,

I need to make sure my string s is in the following format: xxxx-xx-xxx-xxxx

How do check to make sure s is in the desired format, if not return an error message?

Or if length is 13 characters , s = 1305000200923, convert the string to 1305-00-020-0923

Thanks,

Victor
0
Comment
Question by:vcharles
2 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 38724994
How about?

If System.Text.RegularExpressions.Regex.IsMatch(theString, "^\d{13}$") 
    theString = theString.Insert(9, "-").Insert(6, "-").Insert(4, "-")
ElseIf Not System.Text.RegularExpressions.Regex.IsMatch(theString, "^\d{4}-\d{2}-\d{3}-\d{4}$") Then
    ' string does not match; return error
End If

Open in new window

0
 

Author Closing Comment

by:vcharles
ID: 38725065
Thank You!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question