Wednesday, February 20, 2013

Regular Expression - Regex for numeric


    Public Function IsNumeric(ByVal inputStr As String) As Boolean
        Dim _isNumber As Regex = New Regex("(^[+-]?\d+(,?\d*)*\.?\d*([Ee][+-]\d*)?$)|(^[\(]?[\$]?[+-]?\d?(,?\d*)*\.\d+([Ee][+-]\d*)?[\)]?$)")
        Return _isNumber.Match(inputStr).Success
    End Function



    Public Function IsPositiveNumeric(ByVal inputStr As String) As Boolean
        Dim _isNumber As Regex = New Regex("(^[+]?\d+(,?\d*)*\.?\d*([Ee][+]\d*)?$)|(^[\(]?[\$]?[+]?\d?(,?\d*)*\.\d+([Ee][+]\d*)?[\)]?$)")
        Return _isNumber.Match(inputStr).Success
    End Function



    Public Function IsNegative(ByVal inputStr As String) As Boolean
        Dim _isNegativeNumber As Regex = New Regex("^[\(]?[\$]?[-]+\d+(,?\d*)*\.?\d*([Ee][-]+\d*)?[\)]?$|^[-]+[\(]?[\$]?\d+(,?\d*)*\.?\d*([Ee][-]+\d*)?[\)]?$")
        Return _isNegativeNumber.Match(inputStr).Success
    End Function


No comments: