Take Advantage of old rates before 31 December 2011, submit your website to Dir.vc Web Directory Now!
RSS Feed Directory Blog Articles Submit Site Popular Sites Contact Us
Web Directory » Blog
|__ Javascript: Validate Date & Validate future date

Javascript: Validate Date & Validate future date

  - November 5th, 2011 by Web Directory | Posted in Javascript   No Comments »
Email this  Email  |   Print This Post Print This Post     

Javascript: Validate Date & Validate future date

Times where you almost need a Javascript date function, in forms.

Following is what i always use, and it seems to work good for me.

It takes care of 30/ 31 days of the month, and it takes care of the February!

And guess what! it even takes care of leap years too!

I have found numerous Javascript/ jQuery snippets which do the job, but they’re lengthy and untidy.

This one thankfuly is small and works amazingly well

The following is the Javascript code hope you like it!

function isDate(obj)
{
	var dteDate;
	obj1 = obj.split("/");
	obj1[0] = parseInt(obj1[0], 10)-1; //for javascript 0=>January!
	obj1[1] = parseInt(obj1[1], 10);
	obj1[2] = parseInt(obj1[2], 10);
	dteDate=new Date(obj1[2], obj1[0], obj1[1]);
	return ((obj1[1]==dteDate.getDate()) && (obj1[0]==dteDate.getMonth()) && (obj1[2]==dteDate.getFullYear()));
}

//usage :: if ( ! isDate(Form1.BirthDate.value))

You may also want this! How to validate Future date in JavaScript find if the date entered is a future date or not!

Code:

[/php]
function isFutureDate(obj)
{
	var dteDate;
	var now = new Date();
	obj1 = obj.split("/");
	obj1[0] = parseInt(obj1[0], 10)-1;
	obj1[1] = parseInt(obj1[1], 10);
	obj1[2] = parseInt(obj1[2], 10);
	dteDate=new Date(obj1[2], obj1[0], obj1[1]);
	return now > dteDate;
}

//usage :: if (isFutureDate(Form1.AdmitDate.value))
[php]

Hope you find this useful!

link to me!

M.

Tags: , ,

Leave a Reply

Captcha
Enter the letters you see above.



Entries (RSS) and Comments (RSS) Blog – Dir.vc :: Web Directory is proudly powered by WordPress - Site By : M-Solutions India