Search code examples
javaregexseleniumhp-uft

Regular expression for combination of alphanumeric and date in a text


QA POLICY 02/07/2016

I want to validate the above expression. "QA POLICY" should be alphanumeric, and then the date should be validated.

I have used the below expression, and it is failing:

[A-Za-z0-9](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d

image


Solution

  • "QA POLICY" should be alphanumeric, and then the date should be validated.

    I'm assuming you want an alphanumeric text to be validated followed by a date. You can use this regex:

    ^[\w ]*\d{2}\/\d{2}\/\d{4}
    
    • [\w ]* allows any alphanumeric text as well as a space
    • \d{2}\/\d{2}\/\d{4} allows a date in the format dd\mm\yyyy validating only the fact that they should all be numbers

    Regex101 Demo

    Hope this helps!