Data validation - verifying format of a string

Hi,

     I'm having to program data validation for some forms.  Is there some easy VB commands to determine format of a string?  So that for instance:

Easy--
For phone numbers I can check:  '###-###-####'

Difficult--
For address I could verify: '# text'  where # here can be 14, 392, 1298 to allow for different length numbers in addresses?

I'm not sure if that last one would be worth the trouble, but the first one I imagine there's an actual VB string command for checking.

Thanks!

JP
gleznovAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
Regular expression validation:

Simple:
\d{1,3}).?\d{0,3}\s[a-zA-Z]{2,30}\s[a-zA-Z]{2,15}

Complex:
^(?n:(?<address1>(\d{1,5}(\ 1\/[234])?(\x20[A-Z]([a-z])+)+
)|(P\.O\.\ Box\ \d{1,5}))\s{1,2}(?i:(?<address2>(((APT|B
LDG|DEPT|FL|HNGR|LOT|PIER|RM|S(LIP|PC|T(E|OP))|TRLR|UNIT)\x20\w{1,5})|(BSMT|FRNT|LBBY|LOWR|OFC|PH|REAR|SIDE|UPPR)\.?)\s{1,2})?)(?<city>[A-Z]([a-z])+(\.?)(\x20[A-Z]([a-z])+){0,2})\,
\x20(?<state>A[LKSZRAP]|C[AOT]|D[EC]|F[LM]|G[AU]|HI|I[ADL
N]|K[SY]|LA|M[ADEHINOPST]|N[CDEHJMVY]|O[HKR]|P[ARW]|RI|S[CD]
|T[NX]|UT|V[AIT]|W[AIVY])\x20(?<zipcode>(?!0{5})\d{5}(-\d
{4})?))$

Bob
0
gleznovAuthor Commented:
whooooooooah.  Whaaaaaat?

JP
0
gleznovAuthor Commented:
How do I go about implementing that?

JP
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Bob LearnedCommented:
A bit overwhelming, huh?  If you knew it, cool, if not more explanation needed.  

Regular Expressions Tutorial.
http://www.regular-expressions.info/tutorial.html

Regular expressions are a very powerful parsing and validation tool that does the job quite nicely.  It is, unfortunately, very complex to understand at first.

Bob
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bob LearnedCommented:
At the very top of the code view add:
Imports System.Text.RegularExpressions


Add the following function:
  Public Function TestAddress(ByVal inputText As String) As Boolean

    Dim isValid As Boolean

    Try

      Dim patternAddress As String = "\d{1,3}.?\d{0,3}\s[a-zA-Z]{2,30}\s[a-zA-Z]{2,15}"

      Dim addressTest As Regex = New Regex(patternAddress)

      isValid = addressTest.IsMatch(inputText)

    Catch ex As Exception

      MessageBox.Show(ex.ToString)

    End Try

    Return isValid

  End Function


Bob
0
gleznovAuthor Commented:
That turned out to be something a lot harder than I thought, and that reference is excellent, so I'm upping your reward.

JP

Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.