Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
crazyfactory/validation / src / LatinCharValidator.php
Size: Mime:
<?php

namespace CrazyFactory\Validation;

class LatinCharValidator
{
    /**
     * exclude C0 controls (basic latin): https://unicode-table.com/en/blocks/basic-latin/
     *
     * @param string $txt
     *
     * @return bool
     */
    public static function isValid(string $txt): bool
    {
        // remove whitespaces tabs and new-lines
        $txt = preg_replace('/\s+/S', ' ', $txt);

        return empty($txt) || (preg_match('/^[\p{Latin}\p{Common}]+$/u', $txt) > 0
                && preg_match('/[\x{0000}-\x{001F}]/u', $txt) == 0);
    }
}