Closed guilhermemoretto12 closed 3 years ago
<TextInput type="custom" keyboardType="numeric" options={{ mask: state.typeFavoredCompany === 'cpf' ? '999.999.999-99*' : '99.999.999/9999-99', validator: (value) => { return validateCnpj(value) || validateCPF(value); }, getRawValue: (value) => { return (value || '').replace(/\.|\/|-/g, ''); }, }} placeholder="CNPJ ou CPF" value={state.favoredCompany} onChangeText={(text) => setState({ ...state, favoredCompany: text, typeFavoredCompany: text.length > 14 ? 'cnpj' : 'cpf', }) } />
I have just what you need: https://github.com/CaioQuirinoMedeiros/react-native-mask-input
const [cpfCnpj, setCpfCnpj] = React.useState("")
return (
<MaskInput
mask={Masks.BRL_CPF_CNPJ}
value={cpfCnpj}
onChangeText={(masked, unmasked) => {
setCpfCnpj(masked)
}}
keyboardType="numeric"
placeholder="CPF/CNPJ"
/>
)
It would be great if a CNPJ/CPF Mask were added, something like the Cel Phone Mask