473,785 Members | 2,218 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

67 New Member
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 7727
RamananKalirajan
608 Contributor
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
jerrydigital
67 New Member
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(pleas e 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 Recognized Expert Moderator MVP
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
jerrydigital
67 New Member
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 Recognized Expert Moderator MVP
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
2679
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 LCID being set to UK. I have googled extensively but can't work it out. This is my code to give write the current date/time to screen: <% Session.LCID = 2057 Response.Write Now() & "<br>" &
4
43537
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 check. Let's go straight to the point: <script language="JavaScript"> alert("Date: "+Date.parse("2000-01-01"))
2
2839
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 = 345" Note : The above string is stored and the dates are in US format. so
2
3175
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 control does not use any asp.net controls like button or textfield. It uses html "input" for the text field and the button. So after the user has choosen the date and the date is populated in the textfield, I am not able to get the value from the...
10
162682
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
2739
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 format property of a control, it is easy to enter YYYY-MM-DD But it won't work in French versions. In them, AAAA-MM-JJ will. Using format(MyDate,"yyyy-mm-dd") in the controlsource doesn't sem to
1
2565
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". Any ideas? Cheers
10
5822
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 date format in the table design, such as: mm/dd/yyyy? What I've done for years is to store the date format in date fields, then on the forms, based on their region, I would set the date formats on form_load
0
9646
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10157
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10096
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9956
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6742
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5386
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5514
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.