473,503 Members | 12,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

date of birth validation

63 New Member
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 10461
lolodede
63 New Member
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
dmjpro
2,476 Top Contributor
Show us your code what you tried so far?
Apr 9 '09 #3
Dormilich
8,658 Recognized Expert Moderator Expert
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
lolodede
63 New Member
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
  3.  
  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
dmjpro
2,476 Top Contributor
@lolodede
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
gits
5,390 Recognized Expert Moderator Expert
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}/;
  3.  
  4. alert(re.test(s))
kind regards
Apr 9 '09 #7
acoder
16,027 Recognized Expert Moderator MVP
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
gits
5,390 Recognized Expert Moderator Expert
:) ... yep ... thanks for pointing that out ...

kind regards
Apr 9 '09 #9
lolodede
63 New Member
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
gits
5,390 Recognized Expert Moderator Expert
show the code that you have tried.

kind regards
Apr 9 '09 #11
dmjpro
2,476 Top Contributor
Hello all ...What would be my answer ? ;)
Apr 10 '09 #12
lolodede
63 New Member
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

20
11793
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...
4
5342
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...
16
2080
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...
7
15467
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...
2
1203
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...
2
1731
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. ...
3
3378
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...
2
7105
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' ...
1
6778
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,...
0
7098
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
7296
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,...
1
7017
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...
0
5604
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
3186
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...
0
3174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1524
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
405
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...

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.