Skip to content
大纲

日期 YYYY-MM-DD hh:mm:ss

验证日期,符合 YYYY-MM-DD hh:mm:ss 格式。

语法

js
import { ymdhmsReg } from 'warbler-js';
const result = ymdhmsReg(value);

参数

  • value (String) : 待验证字符串。

返回值

Boolean : 是否通过验证,true 通过验证, false 没有通过验证。

源码

js
const ymdhmsReg = (value) => {
  const reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/;
  return reg.test(value);
};

例子

js
import { ymdhmsReg } from 'warbler-js';
const result1 = ymdhmsReg('2021-10-13 17:34:00');
const result2 = ymdhmsReg('13:41:25');

console.log(result1); // true
console.log(result2); // false

添加版本

1.2.0

Released under the MIT License.