473,386 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

validating date in javascript.

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
2 2778
gits
5,390 Expert Mod 4TB
what exactly should happen in the program here and what have you done so far to solve it?
Sep 10 '19 #2
AjayGohil
83 64KB
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

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

Similar topics

1
by: C | last post by:
Hi, I have two input fields on an ASP Page. User enters 2 dates. I want to check that the difference in months does not exceed 360 months. Is this possible in Javascript to get the...
23
by: Ash | last post by:
Hi everyone, This problem has been puzzling me for a fair time now, and has severely frustrated me!! Perhaps I'm just not getting the syntax right, but the problem is rather simple... Take a...
7
by: daniel kaplan | last post by:
hello all, am new to HTML and am in the process of creating a form, no serious headaches, but am stumped on two types of fields. i can take care of these situations using javascript, but was...
1
by: C | last post by:
Hi, I have two input fields on an ASP Page. User enters 2 dates. I want to check that the difference in months does not exceed 360 months. Is this possible in Javascript to get the...
0
by: John | last post by:
Hi Is it possible to use any of the validators such as regular expression validator to validate a date in the format dd/mm/yy? What about an expression in the format 99-99-99? Thanks ...
1
by: viki.sanjeeva | last post by:
Hi, There is a date field in JSP form where user will enter date in dd-mm-yyyy format. Now before saving into DB2, I want to validate the date format against dd-mm-yyyy format and then save into...
1
by: Eugene Anthony | last post by:
I tried validating my dob using the code bellow however I keep getting the message "Enter a valid dob" despite entering a valid dob. String dob = TextBox6.Text + "/" + TextBox7.Text + "/" +...
4
by: loisk | last post by:
Hi, I need to compare a date (on a form )entered by a user with today's date and a date should not be greater than today. The problem, however, the data type for the date is string, not date date...
3
by: SSG001 | last post by:
I want to take the date from user as MONTHYY ----MAR08,FEB08 how do i do thisalso how i add months to the date (yyyy-mm-dd format and get a new date) thanks in advance
6
by: madhuriks | last post by:
hi, in my application i need to enter date nd time in the same textbox...if i run individually it is wrkng fine but wen i combine it is nt wrking fine...can anyone help me out <script...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.