igorescobar / jQuery-Mask-Plugin

A jQuery Plugin to make masks on form fields and HTML elements.
http://igorescobar.github.io/jQuery-Mask-Plugin/
Other
4.77k stars 1.42k forks source link

Mask 00/00/0000 doesnt allow iOS autofill with birthdate #700

Open jstallm opened 5 years ago

jstallm commented 5 years ago

If you create a mask with '00/00/0000', iOS does not allow entering of birthdate from autofill.

Steps to reproduce. Add birthdate to your contact within your contact list Create form with mask '00/00/0000', attempt to autofill.

The field is invalid.

@igorescobar, Is there a way this is handled easily? Essentially what I want is to be able to insert a date such as 05/20/1980 or autofill with 5/20/1980

sacerro commented 2 years ago

Hi, You can add translation settings and add your first day and month digits as optional as this example:

$('#date_field').mask('AB/CB/DBBB', {
    translation: {
      A: { pattern: /[0-3]/, optional: true },
      B: { pattern: /\d/ },
      C: { pattern: /[0-1]/, optional: true },
      D: { pattern: /[1-2]/ },
    }
  });