PHP regex for checking if a string comes from single script whatever it was
<p>M3AAWG (Messaging, Malware and Mobile Anti-Abuse Working Group) delivered instructions for "Best Practices for Unicode Abuse Prevention":</p>

<ul>
<li><a href="https://www.m3aawg.org/sites/default/files/m3aawg-unicode-tutorial-2016-02.pdf" rel="nofollow">M3AAWG Unicode Abuse Overview and Tutorial </a></li>
<li><a href="https://www.m3aawg.org/sites/default/files/m3aawg-unicode-best-practices-2016-02.pdf" rel="nofollow">M3AAWG Best Practices for Unicode Abuse Prevention </a></li>
</ul>

<p>I want to implement this check: username field (PHP) meets this condition:</p>

<pre><code>All characters in each identifier must be **from a single script** or from the combinations:
 - Latin + Han + Hiragana + Katakana
 - Latin + Han + Bopomofo
 - Latin + Han + Hangul
</code></pre>

<p>While the combinations part seems easy to code:</p>

<pre><code>$nonLatinHanHiraganaKatakana = preg_match_all('/[^\\p{Common}\\p{Latin}\\p{Han}\\p{Hiragana}\\p{Katakana}]/u', $value);
$nonLatinHanBopomofo = preg_match_all('/[^\\p{Common}\\p{Latin}\\p{Han}\\p{Bopomofo}]/u', $value);
$nonLatinHanHangul = preg_match_all('/[^\\p{Common}\\p{Latin}\\p{Han}\\p{Hangul}]/u', $value);

// If none of the allowed combinations by M3AAWG, then reject
if ($nonLatinHanHiraganaKatakana &amp;&amp; $nonLatinHanBopomofo &amp;&amp; $nonLatinHanHangul)
{
    // REJECT
}
</code></pre>

<p>Are there an easy way to check if a string comes from a single script? (meaning only {latin}, {greek}, etc... whatever it was? </p>

<p>The trivial staff seems to be checking against each script individually, but there are hundreds, and didn't seem practical, nor performance valuable. Perhaps there is a way to get the 'script' given each character in 'username'? So checking if there is more than one?</p>