validating date in javascript.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Zayn
    New Member
    • Sep 2019
    • 17

    validating date in javascript.

    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

    Code:
    <td><strong>Expiry Date</strong></td>
    		<td><input type="text" id="text7" name="fexpirydate" placeholder="22/08/2030" maxlength="30">
    Last edited by gits; Sep 10 '19, 09:08 AM. Reason: use code tags!
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    what exactly should happen in the program here and what have you done so far to solve it?

    Comment

    • AjayGohil
      New Member
      • Apr 2019
      • 83

      #3
      Hi,

      You can use javascript date function for validate date.

      example:

      Code:
      function validateDate(date) {
          try {
              new Date(date).toISOString();
              return true;
          } catch (e) { 
              return false; 
          }
      }
      In Html you can use date as a input type.It will automatically validate date.

      Example

      Code:
      <input type="date"/>
      Last edited by gits; Jun 2 '20, 10:23 AM. Reason: fix typos in text and added code tags

      Comment

      Working...