Validating MM/YY field for format and that only accepts 1-12 for MM | XM Community
Skip to main content
Question

Validating MM/YY field for format and that only accepts 1-12 for MM

  • September 18, 2019
  • 3 replies
  • 22 views

I would like to create a custom validation regex code that means that participants have to enter a date in the format (MM/YY). I would also like them to have to enter 01-12 for the MM section (to make sure they enter month, not day). Is this possible? Any help would be great 😀

3 replies

fleb
Level 3 ●●●
Forum|alt.badge.img+6
  • Level 3 ●●●
  • October 1, 2019
Hi @miki, definitely yes. Have you tried Google? I'm sure you aren't the first one who wants to implement something like this.

  • Author
  • October 2, 2019
Hi, Thanks for your reply - I have, I've searched all over and couldn't find anything! It is okay though I have just gone for something similar :)

fleb
Level 3 ●●●
Forum|alt.badge.img+6
  • Level 3 ●●●
  • October 2, 2019
OK, I'm sorry then. I found one which does what you want together with the validation of a valid day and year in a few seconds. I have just shortened it: `^([0-2][0-9]|(3)[0-1])(\\/)(((0)[0-9])|((1)[0-2]))$` If you don't want validation of valid days, it would look like this: `^\\d{2}(\\/)(((0)[0-9])|((1)[0-2]))$` or like this: `^\\d{1,2}(\\/)(((0)[0-9])|((1)[0-2]))$` It would be nice if you would post your own answers here and accept them in case you don't need help any more.