<?php

namespace App\Http\Services;

use DateTime;

class CheckParamService
{
    
    public function __construct()
    {
    }
    
    public function LenMToN($str, $m, $n) {
        if (mb_strlen($str) >= $m && mb_strlen($str) <= $n) {
            return true;
        } else {
            return false;
        }
    }
    
    public function isascii($str) {
        if (mb_detect_encoding($str) == "ASCII") {
            return true;
        } else {
            return false;
        }
    }
    
    public function isengnum($str) {
        return (preg_match("/^[a-zA-Z0-9]+$/", $str) == 1);
    }
    
    public function isnum($str) {
        return (preg_match("/^[0-9]+$/", $str) == 1);
    }
    
    public function validateDate($date, $format = 'Y-m-d H:i:s') {
        $d = DateTime::createFromFormat($format, $date);
        return $d && $d->format($format) == $date;
    }
    
    public function RemoveChars($str, $chars) {
        $chars = str_split($chars, 1);
        for ($i = 0; $i < count($chars); $i++) $str = str_replace($chars[$i], "", $str);
        return $str;
    }
    
}
