Skip to main content
Version: Fegg 5.x

Validation::tel

Check the format of a telephone number

Description​

public boolean Validation::tel( string $name, mixed $value, [ mixed $code = '' ] )

Valid when the value contains only digits, -, ( and ), optionally starts with + (country code), and ends with a digit. For example 03-1234-5678, (03)1234-5678 and +81-3-1234-5678.

Arguments​

NameData typeDefaultRemarks
$namestringField name (key of the error message)
$valuemixedValue to check
$codemixed''Error code, array of error code and parameters, or error message (see Configuration)

Example​

Controller
use Fegg\Tool\Validation;

$validation = new Validation();

$validation->tel('success', '03-1234-5678', array('@tel', 'Tel')); // -> true
$validation->tel('failed', '03 1234 5678', array('@tel', 'Tel')); // -> false

var_dump($validation->getErrorMessage());
// -> array('failed' => '<strong>Tel</strong> は登録できない形式です')