I'm setting up a bot flow in my live chat for my users. To retrieve some of their rental, we need to ask the last 4 digits of their credit card then expiration date.
Since I have an open text field for the user input, I've added a regex code, but I'm stuck on the second part.
The first bot question for the last 4 digits: ^\d{4}$
this is working perfectly.
The second bot question should be the expiration date in this format: MMYY or MM/YY or MM-YY
I've created the first part of the regex code for the MM and limit from 1 to 12: (0[1-9]|1[1,2])
Then I've added the - or /. This is where I'm stuck:
- I want to add an option without the
-and/ - I want to add the year format only
YY(notYYYY) and limit it starting from23(2023) and going up to40(2040).
My current code isn't working:
(0[1-9]|1[1,2])(\/|-|)(0[1-9]|23[4,0]
For 23 to 40, use:
Online Demo
The regular expression matches as follows:
\b(?:2[3-9]|3[0-9]|40)\bfor the delimiter, as Barmar said in comments, you can use:
The regular expression matches as follows:
[/-]?Finally
use:
If you need capture groups, feel free to adapt a bit.