Skip to content

PhoneNumberValidator

Use PhoneNumberValidator for phone numbers that may contain spaces, dashes, or a leading plus sign.

Rule::phoneNumber(string $field): PhoneNumberValidator
MethodDescription
length(int $min, int $max)Configure the accepted character length.
required(bool $required = true)Mark the field as required.
optional()Allow a missing number.
validateField(mixed $value)Return the first error or null.
validateFieldAll(mixed $value)Return every applicable error.
use Fynix\Rule;
$validator = Rule::phoneNumber('phone')
->length(10, 16);
$error = $validator->validateField('+1 555-010-0123');

The validator checks the input pattern and its sanitized numeric value. Non-string input and malformed numbers are rejected.