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

date of birth validation

i like to validate date of birth as format dd/mm/yyy i tried everything but is not working
thank you
Apr 9 '09 #1
12 10460
whats wrong with my code
Expand|Select|Wrap|Line Numbers
  1. <!--
  2. function Validate(){
  3. var DOB = new Date(document.forms.DOB.value)
  4. if (DOB == "NaN") {
  5.     alert("DOB required in the format DD/MM/YYYY")
  6.     document.forms.DOB.select.focus()
  7.     return false
  8. }
  9. }
  10. //-->
  11. Date of Birth (dd/mm/yyy): <input type="text" name="DOB" size="30" onblur="Validate()" /></p>
Apr 9 '09 #2
2,476 2GB
Show us your code what you tried so far?
Apr 9 '09 #3
8,658 Expert Mod 8TB
you test whether the Date object is a string, I doubt it will fire. possibly isNAN() or typeof DOB will get you further
Apr 9 '09 #4
i used the above code but it didnt work i dont why
i also i want to validate the the radio buttons so i know if user answered both of the questions
Expand|Select|Wrap|Line Numbers
  1. function checkForm() {
  2. //This fuction shows that the user need to answer Question one
  4. var el = document.forms[0].elements;
  5. for(var i = 0 ; i < el.length ; ++i) {
  6. if(el[i].name == "visites") {
  7. var radiogroup = el[el[i].name];
  8. var itemchecked = false;
  9. for(var j = 0 ; j < radiogroup.length ; ++j) {
  10. if(radiogroup[j].checked) {
  11. itemchecked = true;
  12. break;
  13. }
  14. }
  15. if(!itemchecked) {
  16. alert("Please Answer Question One");
  17. if(el[i].focus)
  18. el[i].focus();
  19. return false;
  20. }
  21. }
  22. }
  23. return true;
  24. }
i used this twice but i dont know how
Apr 9 '09 #5
2,476 2GB
Actually "document.forms" returns Form Collection then how does it work "document.forms.DOB"?

I think when a String is compared with an Object then Object must be converted into String.
Apr 9 '09 #6
5,390 Expert Mod 4TB
to your first question: you could use a simple regExp to check the form's value for the correct format:

Expand|Select|Wrap|Line Numbers
  1. var s  = '01/01/2009';
  2. var re = /\d{2}\/\d{2}\/\d{4}/;
  4. alert(re.test(s))
kind regards
Apr 9 '09 #7
16,027 Expert Mod 8TB
Don't forget the start and end characters:
Expand|Select|Wrap|Line Numbers
  1. var re = /^\d{2}\/\d{2}\/\d{4}$/;
Apr 9 '09 #8
5,390 Expert Mod 4TB
:) ... yep ... thanks for pointing that out ...

kind regards
Apr 9 '09 #9
i used reg expression but is not working right i try to alert it but icant do that i dont know why
thanks for help
Apr 9 '09 #10
5,390 Expert Mod 4TB
show the code that you have tried.

kind regards
Apr 9 '09 #11
2,476 2GB
Hello all ...What would be my answer ? ;)
Apr 10 '09 #12
thanks for help its working now
Apr 12 '09 #13

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

Similar topics

by: Gav | last post by:
I have a database with date of births stored dd/mm/yyyy (english dating system) and =date() returns a date in the same format in my server. how do i find the persons age using these two pieces of...
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
by: KL | last post by:
I am working on a problem and desperately need help! I need to prompt a user for the numerical month of birth, day of birth and year of birth and store it in varialbes and the use the variables...
by: Adrian | last post by:
I hit on this problem converting a VB.NET insurance application to C#. Age next birthday calculated from date of birth is often needed in insurance premium calculations. Originally done using...
by: Matuag | last post by:
Hi All, I am trying to create a form which can calculate with Age and Birth Date fields. I want Age to be calculated based on Birth Date (which I managed to do) but at the same time if Birth...
by: JKChan | last post by:
Hi, I'm an A2 ICT student in second year of college right now and I am working on my database project as my coursework. Its about a dance school with 4 tables Student, Class, Teacher and Enrolment. ...
by: jamieharrop | last post by:
Afternoon all, I've been battling with this all day today and my brain is now pretty much fried. I have one table that lists several details about my customers (name, address, phone, date of...
by: DrSporkeh | last post by:
Hai everyone, i need some help :o basically im trying to set some validation rules for an 'employees' table. firstly i've set it to you have to be 16 to work here under 'Date Of Birth' ...
by: jocelyn88 | last post by:
I would like to identify the Date of Birth, Gender and Age of a Malaysian by extraction the information from the new IC number. The object calculate the Date of Birth, Gender and Age. For example,...
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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
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...

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.