Skip to content

Commit

Permalink
fix(field): Fix phone number validation (Fixes #49) (#50)
Browse files Browse the repository at this point in the history
* chore(field): nitpick empty country validation message
  • Loading branch information
Log1x committed Sep 8, 2022
1 parent 63ec6fb commit 1ceefb3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Plugin Name: Advanced Custom Fields: Phone Number
* Plugin URI: https://github.com/log1x/acf-phone-number
* Description: A real ACF phone number field.
* Version: 1.1.8
* Version: 1.1.9
* Author: Brandon Nifong
* Author URI: https://github.com/log1x
*/
Expand Down
15 changes: 11 additions & 4 deletions src/PhoneNumberField.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,23 @@ public function update_value($value, $post_id, $field)
*/
public function validate_value($valid, $value, $field, $input)
{
if (! is_array($value) || empty($value['number'])) {
if (! empty($value['number']) && ! (new PhoneNumber($value))->isValid()) {
return __('The phone number specified is not valid.', 'acf-phone-number');
}

if (! $field['required']) {
return $valid;
}

if (empty($value['number'])) {
return __('The phone number cannot be empty.', 'acf-phone-number');
}

if (empty($value['country'])) {
return __('The phone number country specified is not valid.', 'acf-phone-number');
return __('The phone number country cannot be empty.', 'acf-phone-number');
}

return (new PhoneNumber($value))->isValid() ?
$valid : __('The phone number specified is not valid.', 'acf-phone-number');
return $valid;
}

/**
Expand Down

0 comments on commit 1ceefb3

Please sign in to comment.