473,387 Members | 1,456 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,387 software developers and data experts.

How do I Verify Date Format - mm/dd/yyyy - using Javascript

Hi,

I have a registration form that uses the javascript validation code I have posted below. I am trying to verify that the user enters a birthdate in the format 01/11/1999

Anyone know how I can incorporate a date format code into my existing code?

Thanks for any help - Jerry

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. <!--
  3. function validate_form ( )
  4. {
  5. valid = true;
  6. if ( document.registration.firstname.value == "")
  7. {
  8. alert ( "Please fill in the 'First Name' box." );
  9. document.registration.firstname.focus();
  10. return false;
  11. }
  12. if ( document.registration.birthdate.value == "")
  13. {
  14. alert ( "Please fill in the 'Birthdate' box." );
  15. document.registration.birthdate.focus();
  16. return false;
  17. }
  18. return valid;
  19. }
  20. //-->
  21. </script>
Nov 6 '08 #1
5 7696
RamananKalirajan
608 512MB
Hello Sir,

Are u using any calendar to get the date value from the user on the user must enter the date in the input in the date format as u have specified.


Regards
Ramanan Kalirajan
Nov 6 '08 #2
Hi,

I am asking the user to enter their birthdate and would prefer if they would enter the date the way I wish.

For instance, I have a form and it says:
Birthdate(please use format mm/dd/yyyy): "text box"

I would like a box to pop up just like my other javascript that says "Please enter a date in the following format "mm/dd/yyyy" if the user fails to do so.

Is there a code I can implement into the code I already have(posted above)?

thanks
Nov 6 '08 #3
acoder
16,027 Expert Mod 8TB
Probably the best method would be to use a regular expression to pattern match the input. Off the top of my head, something like
Expand|Select|Wrap|Line Numbers
  1. /^\d{2}\/\d{2}\/\d{4}$/
Of course, this only matches the format, but doesn't validate that the date is an actual valid one.
Nov 6 '08 #4
Thank you for your post.

I am not sure how to implement this code you speak of into my script. Any ideas?

Thanks
Nov 7 '08 #5
acoder
16,027 Expert Mod 8TB
You can use the RegExp object or use the string methods for matching.

Some links:
http://www.regular-expressions.info/javascript.html
https://developer.mozilla.org/en/Cor...ar_Expressions
https://developer.mozilla.org/En/Cor...Objects/RegExp
Hope those help. If you get stuck, post your code.
Nov 7 '08 #6

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

Similar topics

2
by: Ian | last post by:
I have a problem I hope someone can point out where I am going wrong. I need to store a date/time in a cookie ( ie the date a visitor last visited ) However the date format changes to US, despite...
4
by: Matteo | last post by:
Hy everybody. I'm not a html writer, but a sysadmin who's trying to help a user able to compile an online form with IE but not with Mozilla (Moz1.6, Ns7.1, Firefox 0.8+) due to a javascript date...
2
by: Rahul | last post by:
Hey Guys I have a development environment, in which the whole SQL syntax is stored in the Database. So the syntax in the databse column could be "where BirthDate = '12/31/2005' and ID =...
2
by: kplkumar | last post by:
I have created a asp.net date picker control using Javascript. I wanted to do this to avoid doing post back when the calendar window is launched. It works like charm. But the challenge is - the...
10
by: bonnie.tangyn | last post by:
Dear all In my ASP page, user can enter date in dd/mm/yyyy format. How can I use Javascript to convert dd/mm/yyyy to yyyy-mm-dd hh:mm:ss. Please give me some advices. Cheers Bon
4
by: saintor1 | last post by:
Access 97 - I want the date format YYYY-M M-DD to show everywhere. My problem is that I deal with French and English versions. And don't want to play with Windows Regional Settings. In the...
1
by: saddist | last post by:
Hello, In access 2003 I have date format yyyy/mm/dd, but I want it to be dd/mm/yyyy. I tried to enter dd"/"mm"/"yyyy and dd/mm/yyyy in format property, but it changes automaticly to dd/mm"/yyyy"....
10
by: ARC | last post by:
Hello all, General question for back-end database that has numerous date fields where the database will be used in regions that put the month first, and regions that do not. Should I save a...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.