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.