メインコンテンツまでスキップ
Version: Fegg 5.x(開発版)

Validation::katakana

Check Katakana characters for Japanese language

Description​

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

By default the value must contain only half-width Katakana and half-width symbols (。 to ゚), spaces, (, ) and .. With $zenkakuFlag it must contain only full-width Katakana (ァ-ヶ), ー and full-width spaces.

An empty value ('', null, '0', whitespace only) is not checked and returns true: combine with Validation::required when the field is required. When $name already has an error, the check is skipped and returns false, so only the first error of each field is kept.

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)
$zenkakuFlagbooleanfalsetrue: full-width Katakana only / false: half-width Katakana only

Example​

Controller
use Fegg\Validation;

$validation = new Validation();

$validation->katakana('success', 'テスト', array('@katakana', 'Kana')); // -> true
$validation->katakana('failed', 'テスト', array('@katakana', 'Kana')); // -> false

var_dump($validation->getErrorMessage());
// -> array('failed' => '<strong>Kana</strong> はカタカナで入力してください')

// Full-width Katakana
$validation->katakana('furi', 'テスト', array('@katakana', 'Furigana'), true); // -> true