garganurag893 / react-native-phone-number-input

React Native component for phone number.
MIT License
372 stars 212 forks source link

How to validate phone number on onChangeText method? #119

Open Pradip5495 opened 1 year ago

Pradip5495 commented 1 year ago
 <PhoneInput
                ref={(ref) => {
                  this.phoneInput = ref
                }}
                defaultValue={this.state.inputMobile}
                onChangeText={(text) => {
                  this.setState({ inputMobile: text });
                  var checkValid = this.phoneInput.isValidNumber(JSON.stringify(this.state.inputMobile));
                  alert(checkValid)
                }}
                defaultCode="QA"
                layout="second"
                disableArrowIcon="true"
                placeholder="Enter Mobile Number"
                onChangeFormattedText={(text) => {
                  this.setState({ inputMobile: text });
                }}
              />

I am trying to validate the phone number, on onChangeText method, but whenever I typing a indian phone number +91 9867587654 When I reached to 11 digits it gives true and on 10 digit getting false.