Some handy visual basic regular expression helper functions:

by thebeebs 5/8/2008 9:06:05 AM

Some handy visual basic regular expression helper functions:

Public Class RegExToolbox

    Shared Function IsAlpha(ByVal s As String) As Boolean

        Dim r As New Regex("[^a-zA-Z]")
        Return Not r.IsMatch(s)

    End Function


    Shared Function IsAlphaNumeric(ByVal s As String) As Boolean

        Dim r As New Regex("[^a-zA-Z0-9]")
        Return Not r.IsMatch(s)

    End Function

    Shared Function IsNumericAlpha(ByVal s As String) As Boolean

        Dim r As New Regex("^\d{1,}([A-Za-z])?")
        Return r.IsMatch(s)

    End Function

    Shared Function IsWholeNumber(ByVal s As String) As Boolean

        Dim r As New Regex("([-])?[^0-9]")
        Return Not r.IsMatch(s)

    End Function

    Shared Function IsNumberList(ByVal s As String) As Boolean

        Dim r As New Regex("([-])?\d{1,}([,])([-])?\d{1,}")
        Return r.IsMatch(s)

    End Function

    Shared Function IsNumberRange(ByVal s As String) As Boolean

        Dim r As New Regex("([-])?\d{1,}([-])\d{1,}")
        Return r.IsMatch(s)

    End Function

    Shared Function IsSocialSecurityNumber(ByVal s As String) As Boolean

        Dim r As New Regex("\d{3}-\d{2}-\d{4}")
        Return r.IsMatch(s)

    End Function

    Shared Function IsPhoneNumber(ByVal s As String) As Boolean

        Dim r1 As New Regex("\d{3}-\d{3}-\d{4}")
        Dim r2 As New Regex("\(\d{3}\)\s*\d{3}-\d{4}")

        Return r1.IsMatch(s) OrElse r2.IsMatch(s)

    End Function


    Shared Function IsDatePattern(ByVal s As String) As Boolean
        Dim r1 As New Regex("(of |Of |)(January|February|March|April|May|June|July|August|September|October|November|December) ([1-3]{0,1}[0-9]), ([1-2][0-9]{3})")
        Return r1.IsMatch(s)
    End Function

End
Class

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Related posts

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

8/21/2008 6:12:47 PM

Powered by BlogEngine.NET 1.3.1.0
Theme by Mads Kristensen

About the author

Name of author Author name
Something about me and what I do.

E-mail me Send mail

Calendar

<<  August 2008  >>
MoTuWeThFrSaSu
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567

View posts in large calendar

Recent posts

Recent comments

Authors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Sign in