bhrott / react-native-masked-text

A pure javascript masked text and input text component for React-Native.
MIT License
1.61k stars 249 forks source link

How to set maxLength to custom mask? #155

Closed Luckygirlllll closed 5 years ago

Luckygirlllll commented 5 years ago

I'm creating custom mask to cell phone, how can I limit max length to 10 symbols, fo example?

Here is my code:

<TextInputMask
                        style={styles.input}
                        placeholder='Phone*'
                        type={'cel-phone'}
                        value={this.state.international}
                        maxLength={10}
                        options={{
                             withDDD: true,
                             dddMask: '(999) 999-9999'
                        }}
                        onChangeText={text => {
                            this.setState({
                              international: text
                            })
                          }}
                    ></TextInputMask>
bhrott commented 5 years ago

hey man o/, use the type custom to create custom phone masks.

https://github.com/benhurott/react-native-masked-text#custom

Luckygirlllll commented 5 years ago

@benhurott awesome, it works!

<TextInputMask
                        style={styles.input}
                        placeholder='Phone*'
                        type={'custom'}
                        value={this.state.international}
                        options={{
                             mask: '(999) 999-9999'
                        }}
                        onChangeText={text => {
                            this.setState({
                              international: text
                            })
                          }}
                    ></TextInputMask>