is-date-str
Check if a string is date value
Install
$ npm install is-date-str
Usage
import isDateStr from 'is-date-str';
isDateStr('2023-07-19 12:34:56');
//=> true
isDateStr('unicorn');
//=> false
API
isDateStr(str, options?)
options
Type: object
regexArr
Type: Array<RegExp>
Default: []
Time regex in array list.
import isDateStr from 'is-date-str';
isDateStr('July 19, 2023');
//=> false
const regexArr = [
/^(\d{4})-(\d{2})-(\d{2})[T ](\d{2}):(\d{2})(?::(\d{2}))?(\.\d+)?(Z|[+-]\d{2}:\d{2})?$/,
/^(\d{4})-(\d{2})-(\d{2})$/,
/^(\d{4})\/(\d{2})\/(\d{2})$/,
/^(\d{2}):(\d{2})(?::(\d{2}))?$/,
/^(\d{4})(\d{2})(\d{2})$/
]
isDateStr('20221201', {regexArr});
//=> true