I was writing some validation logic for a reactReact-native app and thought iI had so many bools flying around in my code!
Is there any way to reduce redundancy in this code? or is this the best that can be done.?
_validatePhone() {
if (!validate.validatePhone(this.state.phone)) {
this.setState({ phoneError: true });
return false;
}
return true;
}
_validateName() {
if (!validate.validateName(this.state.name)) {
this.setState({ nameError: true });
return false;
}
return true;
}
_validateForm() {
this._resetErrors(); // Reset errors before validating
if (!this._validateName()) {
return false;
} else if (!this._validatePhone()) {
return false;
}
return true;
}