asking about Input.Text regex samples in adaptivecards

Francisco Lee 1 Reputation point
2023-02-24T01:01:13.56+00:00

I'm asking about Input.Text regex samples in adaptivecards.

In Input.Text we can set any expression on pattern or regex field but

I don't know how to use it.

I would be very helpful if I could get any samples of it.

Community Center | Not monitored
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Alan Farias 755 Reputation points
    2023-02-24T23:17:40.06+00:00

    Here are a few examples of regular expressions that you can use with the Input.Text element in Adaptive Cards:

    • A regex that matches email addresses: ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
    • A regex that matches phone numbers with optional country code: ^\+?\d{1,3}[\s-]?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$
    • A regex that matches date in YYYY-MM-DD format: ^([0-9]{4})-([0-9]{2})-([0-9]{2})$
    • A regex that matches time in 24-hour format: ^([01]?[0-9]|2[0-3]):[0-5][0-9]$
    • A regex that matches credit card numbers: ^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$

    You can modify these regular expressions according to your needs and use them as the value of the pattern field in Input.Text element.

    In an adaptive card Input.Text element, you can use it like this:

    {
      "type": "Input.Text",
      "id": "email",
      "placeholder": "Enter your email address",
      "style": "email",
      "pattern": "^\w+([\\.-]?\\w+)*@\\w+([\\.-]?\\w+)*(\\.\\w{2,3})+$"
    }
    

    Note that the regex pattern needs to be properly escaped in the JSON. The style property is set to "email" to provide an appropriate input keyboard on mobile devices.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.