<?php

namespace Heanup\Frame\Helper;

/**
 * 校验类， 尚未严格验证
 * @package Heanup\Frame\Helper
 */
class Validate extends \Heanup\Frame\Helper
{

    public static function isUrl($url)
    {
        $regex = '/((https?|ftp|news):\/\/)?([a-z]*([a-z0-9\-]*[\.。])+([a-z]{2}|aero|arpa|biz|com|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|pro|travel)|(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))(\/[a-z0-9_\-\.~]+)*(\/([a-z0-9_\-\.]*)(\?[a-z0-9+_\-\.%=&]*)?)?(#[a-z][a-z0-9_]*)?/i';
        return preg_match($regex, $url);
    }

    public static function isEmail($email)
    {
        return preg_match("/^(\w+((-\w+)|(\w.\w+))*)\@(\w+((\.|-)\w+)*\.\w+$)/", $email);
    }

    public static function isMobile($phone)
    {
        return preg_match("/^1\d{10}$/", $phone);
    }

    public static function isCountryMobile($phone)
    {
        return preg_match("/^[1-9]{1}\d{3,14}$/", $phone);
    }


    public static function isDate($str)
    {
        if (!preg_match("/^\d{4}-\d{2}-\d{2}$/", $str)) {
            return FALSE;
        }
        $stamp = strtotime($str);
        if (!is_numeric($stamp)) {
            return FALSE;
        }
        if (checkdate(date('m', $stamp), date('d', $stamp), date('Y', $stamp))) {
            return TRUE;
        }
        return FALSE;
    }

    public static function isIntval($mixed)
    {
        return (preg_match('/^\d*$/', $mixed) == 1);
    }

}