I have this pattern for the Date:
var regexFormat = "\\d{2}-\\d{2}-\\d{4}"
Whenever the user presses one key, I have to check whether the inserted value "may be" a valid Date.
E.G. if the users presses 0, 1, - the "live" validator must be saying "yes, it may be a date", while if the user presses an "a", for example, the validator must return false.
So my question ultimately is: how can I perform a "partial" validation?
Thanks!
OK, so not to be marked as off-topic, I "reward" you with this ugly attempt to solve my problem:
_getDaysList: function (startingDate ,callback) {
var that = this,
currentDate = new Date(),
partialDate = /^(\d(\d(-(\d(\d(-(\d(\d(\d(\d)?)?)?)?)?)?)?)?)?)?$/,
partialYear = /^(\d(\d(\d(\d)?)?)?)?$/,
partialMonth = /^(\d(\d)?)?$/,
partialDay = /^(\d(\d)?)?$/,
list = [];
if (partialDate.test(startingDate)) {
var counter = 0;
while ( startingDate.length != 10 && counter <=5000) {
counter++;
if (// And matches a specific date
that._startsWith(that._dateToString(currentDate),startingDate)) {
// La data segue il parametro.
list.push(that._dateToString(currentDate));
if (that._isFunction(callback)) {
callback(list);
}
return;
}
currentDate = that._addDays(currentDate, -1);
}
}
if (that._isFunction(callback)) {
callback(list);
}
return list;
}