<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/7
 * Time: 17:55
 */

namespace App\Commons\Controller;


class Validation
{
    public static function isUser($data, $config = ['cn' => 0, '_' => 1])
    {
        $parten = "/^([\x{4e00}-\x{9fa5}\w])+([\x{4e00}-\x{9fa5}\w]\d_)?$/u";
        return preg_match($parten, $data);
    }

    public static function isChinease($data)
    {
        $patern = "/^[\x{4e00}-\x{9fa5}]+$/u";
        return preg_match($patern, $data);
    }

    public static function isWords($data)
    {
        $patern = "/^[a-z_A-Z]+$/";
        return preg_match($patern, $data);
    }

    public static function isWordWithNumberEnd($data)
    {
        $patern = "/^\w+[\-]?[_]?[\w\d]?$/";
        return preg_match($patern, $data);
    }

    public static function isEmail($data)
    {
        $patern='/^[\d\w]+([_]?[\-]?[\.]?[\d\w]+)?@[\d\w]+[\.]+[\w]{2,4}/';
        return preg_match($patern,$data);
    }

    public static function isFloat($data)
    {
        $patern = '/^[\d]+\.?\d+$/';
        return preg_match($patern, $data);
    }
}