<?php

namespace App\Sports\Controller;

/**
 * Class Validation
 * @package App\Sports\Controller
 * 验证器
 */
class Validation
{

    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);
    }

    /**
     * @param $data
     * @return false|int
     * 验证账号规则：字母开头，允许5-16字节，允许字母数字下划线
     */
    public static function isAccount($data){
        $patern = '/[a-zA-Z][a-zA-Z0-9_]{4,15}$/';
        return preg_match($patern, $data);
    }

    /**
     * @param $data
     * @return false|int
     * 验证密码 以字母开头，长度在6~18之间，只能包含字母、数字和下划线
     */
    public static function isPassword($data){
        $patern = '/^[a-zA-Z]\w{5,17}$/';
        return preg_match($patern, $data);
    }

    /**
     * @param $data
     * @return false|int
     * 验证密保问题答案 中文字母数字
     */
    public static function isAnswer($data){
        $patern = '/^[\u4e00-\u9fa5a-zA-Z-z0-9]+$/';
        return preg_match($patern, $data);
    }

    /**
     * @param $data
     * @return false|int
     * 验证提款密码 以字母开头，长度在6~18之间，只能包含字母、数字和下划线
     */
    public static function isWmpassword($data){
        $patern = '/^[a-zA-Z]\w{5,17}$/';
        return preg_match($patern, $data);
    }
}