javascript - Date regex validator for the following format "MMM d, y HH:mm" -
can me create regex validator dates in following format: mmm d, y hh:mm
example: aug 7, 2015 00:00
have started this: ^jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec
have no idea how continue (regex new me)
you can use square brackets represent range between 2 characters.
to dates between 1 , 9 use [1-9].
to dates between 10 , 29 use [1-2][0-9].
to dates between 30 , 31 use 3[0-1].
combined [1-9]|[1-2][0-9]|3[0-1]. can reduced [1-2]?[0-9]|3[0-1]. [0-9] same \d means digit. can further reduced [1-2]?\d|3[0-1].
for years above 1900 can use 19\d\d , between 2000 , 2199 use 2[0-1]\d\d.
you point. in end should end like:
var r = /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\s+([1-2]?\d|3[01]),\s+(19\d\d|2[0-1]\d\d)\s+([0-1]?\d|2[0-4]):([0-5]?\d|60)$/ r.test('aug 7, 2015 00:00'); // true 'aug 7, 2015 00:00'.split(r); // ["", "aug", "7", "2015", "00", "00", ""]
after have segments of date in strings validate each 1 based on rules may have.
Comments
Post a Comment