Format date with jQuery

0

I'm currently formatting a date field with the following mask:

$("input[type='date']").mask('dD/mM/yYYY', {
                                        translation: {
                                                        d: {pattern: /[0-3]/},
                                                        D: {pattern: /[0-9]/},
                                                        m: {pattern: /[0-1]/},
                                                        M: {pattern: /[0-2]/},
                                                        y: {pattern: /[1-2]/},
                                                        Y: {pattern: /[0-9]/},
                                                        Y: {pattern: /[0-9]/},
                                                        Y: {pattern: /[0-9]/}
                                                      }
                                                });

But I would at least like to prevent that in the first occurrence, if the day starts with digit 3 to allow the next digit to be only 0 or 1, that would result in days 30 and 31.

    
asked by anonymous 23.10.2016 / 18:22

1 answer

0

You can change to use D: {pattern: /[^3][0-9]|3[0-1]/} , or put a single digit in the mask and make a simpler expression: mask('d/mM/yYYY') and use d: {pattern: /[0-2][0-9]|3[0-1]/} .

    
23.10.2016 / 19:49