Skip to content

Commit

Permalink
Update validate-day-time.js
Browse files Browse the repository at this point in the history
检测 是否是(YYYY|yyyy)-MM-(DD|dd) or (YYYY|yyyy)-MM-(DD|dd) (HH|hh):mm:(SS|ss)格式的时间字符串
  • Loading branch information
Rain120 authored Apr 8, 2019
1 parent 311147b commit 705fe18
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions validate-day-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@ function validateTime(value) {
}
return true;
}

const validateDayFormat = (value) => {
// tslint:disable-next-line:max-line-length
const dayRegex = /(^[Y|y]{4}([-\/\._])M{2}([-\/\._])[D|d]{2})|(^M{2}([-\/\._])[D|d]{2}([-\/\._])[Y|y]{4})$/;
if (!dayRegex.test(value)) {
return false;
}
return true;
}

const validateTimeFormat = (value) => {
// tslint:disable-next-line:max-line-length
const timeRegex = /(^[Y|y]{4}([-\/\._])M{2}([-\/\._])[D|d]{2})|(^M{2}([-\/\._])[D|d]{2}([-\/\._])[Y|y]{4})\s+[H|h]{2}:m{2}:[S|s]{2}$/;
if (!timeRegex.test(value)) {
return false;
}
return true;
}
console.log(validateDate('2018-02-28'))
console.log(validateDate('2018-02-31'))
console.log(validateTime('2018-01-28 12:20:21'))
Expand Down

0 comments on commit 705fe18

Please sign in to comment.