thebeebs | Some handy visual basic regular expression helper functions:
thebeebs
Zeroing the desk - Ignore the design
 
 

Some handy visual basic regular expression helper functions:

by thebeebs 8. May 2008 01:06

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

Tags:

Comments are closed