Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if ( phoneNumber.search( /[a-z,A-Z]/ ) > -1 ) {
return {
error: 'phone_number_contains_letters',
message: i18n.translate( 'Phone numbers cannot contain letters' ),
};
}
if ( phoneNumber.search( /[^0-9,\+]/ ) > -1 ) {
return {
error: 'phone_number_contains_special_characters',
message: i18n.translate( 'Phone numbers cannot contain special characters' ),
};
}
// phone module validates mobile numbers
if ( ! phone( phoneNumber ).length ) {
return {
error: 'phone_number_invalid',
message: i18n.translate( 'That phone number does not appear to be valid' ),
};
}
return {
info: 'phone_number_valid',
message: i18n.translate( 'Valid phone number' ),
};
}
const isCellphoneNumberValid = (value) => isValidNumber(parse(value, 'ZA')) && phone(value, 'ZAF').length > 0;
const onUserChange = field => event => {
let { value } = event.target;
if (field === 'privateAccount') {
value = event.target.checked;
}
if (field === 'email') {
setError({ ...error, email: value && !emailValidator.validate(value) });
}
if (field === 'phoneNumber') {
const [formattedPhoneNumber] = phone(value);
setError({ ...error, phoneNumber: value && !formattedPhoneNumber });
}
setUser({
...user,
[field]: value,
});
};