Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2013-12-16
4
Medium Priority
?
434 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 1000 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 64

Accepted Solution

by:
Fernando Soto earned 1000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…

916 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