A
A
Aleksei Podgaev2014-02-28 13:09:23
JavaScript
Aleksei Podgaev, 2014-02-28 13:09:23

Recovering date from formatted string in Angular?

Briefly, the task can be described as restoring a date formatted with a $filter('date')(date[, format])string in Angular.
That is, suppose there is a date obtained something like this:

$scope.userStartDate = $filter('date')(date, format)

$scope.userStartDate and format are known. It is necessary to restore the date object of the Date() type from them.
Task number 2: you need to get a regular expression from the given format to validate the date input field using ng-pattern.
My way of thinking is this: you first need to parse the format string with a regular expression in order to isolate control strings like MM or yyyy from there, use this string to compose a regular expression that would simultaneously serve as a validator for the input field and a parser of the entered value for substitution later in Date.setFullYear ().
I will dig regular expressions myself, but if someone can quickly offer a ready-made solution (without using external libraries), I will be grateful.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Pushkarev, 2014-02-28
@rock

Date.parse, Sugar.js , Moment.js

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question