Validation::katakana
Check Katakana chracter for Japanese language
Description
public boolean Validation::katakana( string $name, mixed $value, [ mixed $code = '', boolean $zenkakuFlag = false ] )
Arguments
Name | Data type | Default | Remarks |
---|---|---|---|
$name | string | Item label | |
$value | mixed | Check field value | |
$code | mixed | "" | Error code or Error message |
$zenkakuFlag | boolean | false | Required full-width Katakana only flag |
Example
Controller
$validation = $this->getClass('Validation');
// If $value has only Japanese Katakana
$successName = 'Success Field';
$successVar = 'テスト';
$validation->katakana('success', $successVar, array('@katakana', $successName));
var_dump($validation->isError()); // -> false
var_dump($validation->getErrorMessage()); // -> null
// If $value has not only Japanese Katakana
$failedName = 'Failed Field';
$failedVar = 'てすと';
$validation->katakana('failed', $failedVar, array('@katakana', $failedName));
var_dump($validation->isError()); // -> true
var_dump($validation->getErrorMessage());
// -> "failed" => "<strong>Failed Field</strong> はカタカナで入力してください"
Optional Flag
Controller
// If $value has half-width Katakana with disabled $zenkakuFlag
$successName = 'Success Field';
$successVar = 'テスト';
$validation->katakana('success', $successVar, array('@katakana', $successName));
var_dump($validation->isError()); // -> false
var_dump($validation->getErrorMessage()); // -> null
// If $value has half-width Katakana with enabled $zenkakuFlag
$failedName = 'Failed Field';
$failedVar = 'テスト';
$validation->katakana('failed', $failedVar, array('@katakana', $failedName), true);
var_dump($validation->isError()); // -> true
var_dump($validation->getErrorMessage());
// -> "failed" => "<strong>Failed Field</strong> はカタカナで入力してください"