I have a code to validate the date in the form of MMYY format.This shows dynamic popup dialog box before submitting the button. For this the code is given below as:
<ext:text name="caseDetailForm" property="phaseData.phaseDateExpiration" styleId="_dateExp"
style="width:100px" maxlength="4" titleKey="prompt.exp.date" onkeyup="validateCardExpiry(this);" />
and the function is:
function validateCardExpiry(field) {
var cardExpRegEx1or2char = /^(0[1-9]?|1[0-2]?)$/;
var cardExpRegEx3or4char = /^(0[1-9]?|1[0-2])[0-9]?[0-9]?$/;
var cardExpDate = field.value;
var msg = '<bean:message key="errors.bad.input.characters.detected"/> - '+cardExpDate;
+ '\n' + "<bean:message key="prompt.exp.date"/>";
var failed = false;
for (var x = cardExpDate.length; x >= 0; x--) {
cardExpDate = cardExpDate.substring(0, x);
if (cardExpDate.length > 0 &&
((cardExpDate.length <= 2 && !cardExpRegEx1or2char.test(cardExpDate))
|| (cardExpDate.length > 2 && !cardExpRegEx3or4char.test(cardExpDate)))) {
failed = true;
}
else {
field.value = cardExpDate;
break;
}
}
if (failed) {
alert(msg);
}
}
for MMYY validation is working fine with above code. But i need MM/DD/YYYY validation. For this how can i validate with popup window in the same scenario.
You can do something like:
but the format mm/dd/yyyy is not used by that many people, most use either dd/mm/yyyy or yyyy-mm-dd.