insin / react-maskedinput

Masked <input/> React component
http://insin.github.io/react-maskedinput/
MIT License
730 stars 197 forks source link

Pass value to formatCharacters validate #91

Open MikeDevice opened 7 years ago

MikeDevice commented 7 years ago

How about passing input value to validate method in formatCharacters. I think it will be convenient. Example

<MaskedInput
  formatCharacters={{
    'w': {
      validate(char, value) {
        return value.length === 1 && char === 'w' || value.length === 2 && char === 'W';
      },
    }
  }}
/>

This example does not make sense, but this functional can be useful.

jainprash commented 6 years ago

+1. This is needed, if we need to validate the expiry-date is between 0 and 12, and return empty otherwise. Without this, I'm not sure how you can achieve this feature, as this function gives single char at a time.