Solved

Functin to find strings that start with a alpa and then contain numbers visual basic .net

Posted on 2013-12-16
4
412 Views
Last Modified: 2013-12-18
I need a function that will look at a string to determine it's in the correct format.
j00000
p00000
The string must start with a j or p and then contain numbers after that.  The numbers will be random and might contain more/less digits.
0
Comment
Question by:chadmanvb
  • 2
4 Comments
 
LVL 2

Assisted Solution

by:DiscGolfDad
DiscGolfDad earned 250 total points
ID: 39722904
blnIsValid = (strTest Like "P*" Or strTest Like "J*") And IsNumeric(Mid(strTest, 2)
0
 
LVL 2

Expert Comment

by:DiscGolfDad
ID: 39722907
Oops - missed one ")" at the end.
0
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 250 total points
ID: 39723967
Hi chadmanvb;

You can use this regular expression to verify the proper string input.

Imports System.Text.RegularExpressions


' The pattern for regex to look for
Dim pattern As String = "((?i)^[jp]\d+?)"
' The string to be verified
Dim input As String = "p12345"

' Test to see if the regex pattern matches the input string
If Regex.Match(input, pattern).Success Then
   ' This is executed if the regex matches the input string
End If

Open in new window

0
 

Author Closing Comment

by:chadmanvb
ID: 39726413
Both worked great!  Thanks guys.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

867 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now