type(); } /** * Checks the number. * * @param Field $field Field being validated. * @param mixed $value Sanitised value. * * @return ValidationError|null The failure, or null when the value passes. */ public function validate( Field $field, mixed $value ): ?ValidationError { $digits = (string) preg_replace( '/\D/', '', (string) $value ); $length = strlen( $digits ); if ( $length >= self::MIN_DIGITS && $length <= self::MAX_DIGITS ) { return null; } return new ValidationError( '', 'invalid_phone', __( 'Please enter a valid phone number.', 'devplugins-custom-form-builder' ), array( 'digits' => $length ) ); } }