Regular expression to validate single word - ( Uppercase A to Z , Number & Period without any space) RRS feed

  • Question

  • I need help for regular expression for vba. I want to validate ranges which have product ID. The valid Product ID are the one which have Uppercase chars or number or dot like (A102345 , T.35DG). I have tried the below code but not able to figure out. 

    Public Function ValidNumber(ByVal strNumber As String) As Boolean
        With CreateObject("VBScript.RegExp")
            .Global = True
            .Pattern = "[A-Z0-9.]"
            ValidNumber = .test(strNumber)
        End With
    End Function
    Sub test()
    Debug.Print ValidNumber("AAACVD12@")
    End Sub

    Monday, October 13, 2014 3:53 PM

All replies

  • Hi,

    Thank you for posting in the MSDN Forum.

    Since the issue is more related to the Regex of VBA language instead of Excel Object Model, I'd like to move it to VBA forum.

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us.

    Thanks for your understanding.

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, October 14, 2014 2:33 AM
  • Hi Santosh,

    Check if this works - .Pattern = "[A-Z][0-9][_\.]"



    • Proposed as answer by Amol Gargote Tuesday, October 21, 2014 5:27 AM
    Thursday, October 16, 2014 1:30 PM