Solved

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

Posted on 2013-12-16
4
409 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
Comment Utility
blnIsValid = (strTest Like "P*" Or strTest Like "J*") And IsNumeric(Mid(strTest, 2)
0
 
LVL 2

Expert Comment

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

Accepted Solution

by:
Fernando Soto earned 250 total points
Comment Utility
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
Comment Utility
Both worked great!  Thanks guys.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video discusses moving either the default database or any database to a new volume.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

10 Experts available now in Live!

Get 1:1 Help Now