mysql正则匹配Y-m-d Y/m/dYmd

mysql正则匹配Y-m-d Y/m/dYmd

 

//判断时间格式Y-m-d H:i:s或Y/m/d H:i:s
public function checkDateValid($field){
$sql = "SELECT count(*) as count FROM ".$this->tableName." WHERE ".$field."!='' and ".$field." NOT REGEXP '^[0-9]{4}[-\/][0-9]{1,2}[-\/][0-9]{1,2} [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}$'";
\PhalApi\DI()->logger->log('log', 'log', ['msg'=>$sql]);
return $this->getORM()->queryAll($sql);
}
//判断时间格式Y-m-d或Y/m/d或Ymd
public function checkDtValid($field){
$sql = "SELECT count(*) as count FROM ".$this->tableName." WHERE ".$field."!='' and ".$field." NOT REGEXP '^[0-9]{4}(?:-|/)?[0-9]{1,2}(?:-|/)?[0-9]{1,2}$'";
\PhalApi\DI()->logger->log('log', 'log', ['msg========='=>$sql]);
return $this->getORM()->queryAll($sql);
}

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: