Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is no such validator for chinese or japanese in ZF2.</p> <p>What you can do is building your own small validator class. I combined <a href="https://stackoverflow.com/questions/4923319/php-check-if-the-string-has-chinese-chars">Php check if the string has Chinese chars</a> and <a href="https://stackoverflow.com/questions/2856942/how-to-check-if-the-word-is-japanese-or-english-using-php">How to check if the word is Japanese or English using PHP</a> to build these two small validators by <a href="https://github.com/zendframework/zf2/blob/release-2.1.3/library/Zend/Validator/AbstractValidator.php" rel="nofollow noreferrer">extending the abstract validator</a> for you:</p> <pre class="lang-php prettyprint-override"><code>namespace MyApp\Validator; use Zend\Validator\AbstractValidator; // forgive the name of this class class IsNotOrientalLanguage extends AbstractValidator { /** * {@inheritDoc} */ public function isValid($value) { $this-&gt;abstractOptions['messages'] = array(); if (preg_match('/\p{Han}+/u', $value)) { $this-&gt;abstractOptions['messages'][] = 'Chinese not allowed.'; } if (preg_match('/[\x{4E00}-\x{9FBF}]/u', $value)) { $this-&gt;abstractOptions['messages'][] = 'Kankji not allowed.'; } if (preg_match('/[\x{3040}-\x{309F}]/u', $value)) { $this-&gt;abstractOptions['messages'][] = 'Hiragana not allowed.'; } if (preg_match('/[\x{30A0}-\x{30FF}]/u', $value)) { $this-&gt;abstractOptions['messages'][] = 'Katakana not allowed.'; } return ! $this-&gt;abstractOptions['messages']; } } </code></pre> <p>You can now use this validator wherever you want:</p> <pre class="lang-php prettyprint-override"><code>use Zend\InputFilter\Input; use MyApp\Validator\IsNotOrientalLanguage; $input = new Input('blog_post'); $input-&gt;getValidatorChain()-&gt;attach(new IsNotOrientalLanguage()); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload