Solved

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

Posted on 2013-12-16
4
420 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
[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
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 63

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

734 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