Solved

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

Posted on 2012-12-27
2
233 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

762 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