clientside validation for date
-
Hi all i am using asp.net , C# , ajax1.0 i want to know is it possible to perform client side validation for not allowing date before current date + 5 that is if i am entering a date today(11-09-08) then it should not allow any date before 16-09-08 Please help Thank you.
imran khan
-
Hi all i am using asp.net , C# , ajax1.0 i want to know is it possible to perform client side validation for not allowing date before current date + 5 that is if i am entering a date today(11-09-08) then it should not allow any date before 16-09-08 Please help Thank you.
imran khan
-
Hi all i am using asp.net , C# , ajax1.0 i want to know is it possible to perform client side validation for not allowing date before current date + 5 that is if i am entering a date today(11-09-08) then it should not allow any date before 16-09-08 Please help Thank you.
imran khan
You would have to parse the string and create a Date object from it, and create a Date object to compare it with. Something like:
// verify string
if (/^\d\d-\d\d-\d\d$/.test(input)) {
// get current time
var today = new Date();
// get current + 5 days
var limit = new Date(today.getYear(), today.getMonth(), today.getDay()+5);
// split input
var arr = input.split('-');
// create Date from input
var inputDate = new Date(parseInt(arr[2],10), parseInt(arr[1],10)-1, parseInt(arr[0],10));
// compare dates
if (inputDate >= limit) {
alert('Date is ok.');
}
}Despite everything, the person most likely to be fooling you next is yourself.