Solved

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

Posted on 2012-12-27
2
239 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

696 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