By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,140 Members | 1,361 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,140 IT Pros & Developers. It's quick & easy.

validating date in javascript.

P: 17
I'm working on an assignment for school where we're working with JavaScript (I'm only allowed to use JavaScript) to validate a form for a payment page. It's my first time working with JavaScript so and I feel a bit lost..I need to link my html and javascript with a button

HTML CODE

Expand|Select|Wrap|Line Numbers
  1. <td><strong>Expiry Date</strong></td>
  2.         <td><input type="text" id="text7" name="fexpirydate" placeholder="22/08/2030" maxlength="30">
Sep 10 '19 #1
Share this Question
Share on Google+
2 Replies


gits
Expert Mod 5K+
P: 5,389
what exactly should happen in the program here and what have you done so far to solve it?
Sep 10 '19 #2

P: 53
Hi,

You can use javascript date function for validate date.

example:

Expand|Select|Wrap|Line Numbers
  1. function validateDate(date) {
  2.     try {
  3.         new Date(date).toISOString();
  4.         return true;
  5.     } catch (e) { 
  6.         return false; 
  7.     }
  8. }
In Html you can use date as a input type.It will automatically validate date.

Example

Expand|Select|Wrap|Line Numbers
  1. <input type="date"/>
Jun 2 '20 #3

Post your reply

Sign in to post your reply or Sign up for a free account.