CaioQuirinoMedeiros / react-native-mask-input

🎭:iphone: A simple and effective Text Input with mask for ReactNative on iOS and Android. Includes obfuscation characters feature.
https://www.npmjs.com/package/react-native-mask-input
MIT License
309 stars 31 forks source link

Accept regex quantifier #1

Closed juanlatorre closed 3 years ago

juanlatorre commented 3 years ago

Hi, currently this kind of regex are not working at all.

\d{1,3}

CaioQuirinoMedeiros commented 3 years ago

Hi @juanlatorre, I'll take a look at this as soon as I can

CaioQuirinoMedeiros commented 3 years ago

@juanlatorre the validation is done for each character against a item on the mask array, so the regex /\d{1,3}/ will actually behave the same as /\d/. If you want to allow three digits in sequence you should use [/\d/, /\d/, /\d/].

If you need some dinamically rule, use a function to do your logic, like that:

const myMask = (value: string) => {
  if (something) {
    return [/\d/]
  } else {
    return [/\d/, /\d/, /\d/]
  }
}
juanlatorre commented 3 years ago

Thanks for the quick validation, I will implement a custom mask function then !