Solved

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

Posted on 2013-12-16
4
413 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
rebind a grid after user clicks on node in treeview 1 34
C# bracket error 3 30
Alert on Server memory 2 20
VB: Convert 2 dates to specific format 24 48
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

776 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