How validate mobile number in react native accept the only numeric value.
<TextInput
ref='mobileNo'
keyboardType="numeric"
style={[styles.textInput, { width: '100%' }]}
placeholder='Enter mobile number'
onChangeText={(value) => this.handleChange('mobileNo', value)} />
I have used keyboardType="numeric"
but its accept special character also so I want to accept the only numeric value.
Use this validation.
mobilevalidate(text) {
const reg = /^[0]?[789]\d{9}$/;
if (reg.test(text) === false) {
this.setState({
mobilevalidate: false,
telephone: text,
});
return false;
} else {
this.setState({
mobilevalidate: true,
telephone: text,
message: '',
});
return true;
}
}
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