We're developing program on React Native, and I have a question. How to make a text input mask for ZIP code and mobile phone number via React Native?
Here's a sample:
import TextInputMask from 'react-native-text-input-mask'; ... <TextInputMask onChangeText={(formatted, extracted) => { console. log(formatted) // +1 (123) 456-78-90 console. log(extracted) // 1234567890 }} mask={"+1 ([000]) [000] [00] [00]"} /> ...
Customize input masks from the field property settingIn the Navigation Pane, right-click the object and click Design View on the shortcut menu. Click the field where you want to create the custom input mask. In the Field Properties area, click the Input Mask text box, and then type your custom mask.
Use caretHidden={true} if you want to disable all operation like Cut Paste Copy. It will also hide your cursor as well.
Check out this library. https://github.com/wix/react-native-ui-lib
(or directly this: https://github.com/wix/react-native-ui-lib#masked-input)
It allows you to render custom masked input in any format you want.
You can use it as follow: (this is an example for a phone number)
import {MaskedInput} from 'react-native-ui-lib'
// in your render...
<MaskedInput
renderMaskedText={this.renderMaskedInput}
caretHidden
keyboardType={'numeric'}
/>
renderMaskedInput(value) {
return (
<View>
<Text>
{value.substr(0, 3)} - {value.substr(3, 10)}
<Text>
<View>
);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With