HTML Markup :
<asp:Button ID="btnCOBDC" runat="server" Text="COBD Close" OnClick="COBD_Click" OnClientClick="return show_COBDprompt();" />
<asp:HiddenField ID="hdnCOBDValue" runat="server" />
<asp:HiddenField ID="hdnExpectedCOBD" runat="server" />
Javascript to Handle prompt and input value [limitation : only one input value] [for multiple value input use div]
<script type="text/javascript" language="javascript">
function isLeapYear() {
return (year % 4 != 0 ? false :
( year % 100 != 0? true:
( year % 1000 != 0? false : true)));
}
function isValidDate(date_string) {
var days = [0,31,28,31,30,31,30,31,31,30,31,30,31];
var year, month, day, date_parts = null;
var rtrn = false;
var format = 'mm/dd/yyyy';
var decisionTree = {
'm/d/y':{
're':/^(\d{1,2})[./-](\d{1,2})[./-](\d{2}|\d{4})$/,
'month': 1,'day': 2, year: 3
},
'mm/dd/yy':{
're':/^(\d{1,2})[./-](\d{1,2})[./-](\d{2})$/,
'month': 1,'day': 2, year: 3
},
'mm/dd/yyyy':{
're':/^(\d{1,2})[./-](\d{1,2})[./-](\d{4})$/,
'month': 1,'day': 2, year: 3
},
'y/m/d':{
're':/^(\d{2}|\d{4})[./-](\d{1,2})[./-](\d{1,2})$/,
'month': 2,'day': 3, year: 1
},
'yy/mm/dd':{
're':/^(\d{1,2})[./-](\d{1,2})[./-](\d{1,2})$/,
'month': 2,'day': 3, year: 1
},
'yyyy/mm/dd':{
're':/^(\d{4})[./-](\d{1,2})[./-](\d{1,2})$/,
'month': 2,'day': 3, year: 1
}
};
var test = decisionTree[format];
if (test) {
date_parts = date_string.match(test.re);
if (date_parts) {
year = date_parts[test.year] * 1;
month = date_parts[test.month] * 1;
day = date_parts[test.day] * 1;
test = (month == 2 &&
isLeapYear() &&
29 ||
days[month] || 0);
rtrn = 1 <= day && day <= test;
}
}
return rtrn;
}
function show_COBDprompt() {
var expectedCOBD = document.getElementById('hdnExpectedCOBD').value;
var cobd = prompt("Please enter COB Date [mm/dd/yyyy] :", expectedCOBD);
if (cobd != null && cobd != "") {
if(!isValidDate(cobd)){ alert('Please enter the date in correct format i.e. mm/dd/yyyy'); return false; }
document.getElementById('hdnCOBDValue').value = cobd;
return true;
}
return false;
}
</script>
No comments:
Post a Comment