react-input-validator is input super class validator
npm install react-input-validator
onInputChange, and to pass the REQUIRED params which is (nodeElement, PatternValidatorFn) .
npm install react-input-validator
npm run build
file:///{Your Path}/react-input-validator/Client/index.html
import InputValidator from 'react-input-validator';
class PhoneInput extends InputValidator {
constructor(props) {
super(props);
}
render() {
return (
ref={node => this.phoneRef = node}
onChange={() => { super.onInputChange(this.phoneRef, this.validatePhone) }}
className="form-control" id="phone-input" />
)
}
validatePhone() {
//Pattern: xxx-xxxxxxx || xxxxxxxxxx
let phoneRegex = /^[0-9][0-9]0-9[0-9][0-9][0-9][0-9][0-9][0-9][0-9]$/;
if(phoneRegex.test(this.phoneRef.value)) {
return true;
} else if (!phoneRegex.test(this.phoneRef.value)) {
return false;
}
}
}
export default PhoneInput;
``