We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,524 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Datet of Birth Validation - JS or PHP?

Hey guys,

I was wondering if there is possibly an "onBlurr" or "onChange" way I can check using JavaScript if a Birth date is correct I've seen a couple but I have a pretty simplistic way about how I want to get it done.

Basically what I would like to do is check the months and check if they've entered an incorrect date for them (I will be using the 3 drop down boxes method).

so if a users selects 30-31 for feb i want it to check the minute its changed for either one in order to notify the user that its an invalid birth date, which would apply for all months totalling 30 days.

also the same for the leap year of feb if its 29 but the year is not divisible by 4 then the date is still invalid (I have a rough sketch idea of how to validate this however it would be very handy if i could do it onblurr like i said).

Thanks in advance

3
Contributors
5
Replies
4 Hours
Discussion Span
1 Year Ago
Last Updated
6
Views
ghost_from_sa
Junior Poster in Training
53 posts since May 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

onChange onBlur are for javascript. there can be made a date check without any problems

sv3tli0
Junior Poster in Training
83 posts since Aug 2011
Reputation Points: 10
Solved Threads: 18
Skill Endorsements: 0

which one of the two is faster/More reliable?
atm im doing it in javascript

ghost_from_sa
Junior Poster in Training
53 posts since May 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Its depending what will be the inputs which(select boxes or text input) you will use and when you will make the check while selecting date, or when submitting your form

sv3tli0
Junior Poster in Training
83 posts since Aug 2011
Reputation Points: 10
Solved Threads: 18
Skill Endorsements: 0

Ok so this is the code I have a.t.m
However it only works on form submission.
This is the exact code I would like to implement "onChange".

Any help would be GREAT thanks again :)

function check(theForm)
{
   //=======================================================================
   //			Variables to check correct issuement later
   //=======================================================================

   var checker;
   //  Select fields alternate test
   var day = theForm.day.value;
   var month = theForm.month.value;
   var year = theForm.year.value;
   
   var age = document.getElementById('userAge');


   if (month == "February")
   {
	if (day	> 29)
	{
	   var adder = age.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
	   adder = '<label class="incorrect" id="userAge"> *Date Of birth*: </label>'; // changes the current label tag into the innerHTML field
	   age.innerHTML = adder; // changes the innerHTML to equal the adder
	   checker = false; // checker becomes false and needs to show the user
	}
	else if (( day > 28) && ( year%4 != 0 ))
	{
	   var adder = age.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
	   adder = '<label class="incorrect" id="userAge"> *Date Of birth*: </label>'; // changes the current label tag into the innerHTML field
	   age.innerHTML = adder; // changes the innerHTML to equal the adder
	   checker = false; // checker becomes false and needs to show the user
	}
	else
	{
	   var adder = age.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
	   adder = '<label class="loginLabel" id="userAge"> Date Of birth: </label>'; // changes the current label tag into the innerHTML field
	   age.innerHTML = adder; // changes the innerHTML to equal the adder
	}
   }
   else if ( ( month == "April" ) || ( month == "June") || ( month == "September") || ( month == "November") )
   {
	if (day > 30 )
	{
	   var adder = age.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
	   adder = '<label class="incorrect" id="userAge"> *Date Of birth*: </label>'; // changes the current label tag into the innerHTML field
	   age.innerHTML = adder; // changes the innerHTML to equal the adder
	   checker = false; // checker becomes false and needs to show the user
	}
	else
	{
	   var adder = age.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
	   adder = '<label class="loginLabel" id="userAge"> Date Of birth: </label>'; // changes the current label tag into the innerHTML field
	   age.innerHTML = adder; // changes the innerHTML to equal the adder
	}
   }
   // see if the user has false or true contact details... if false
   if (checker == false)
   {
 	alert("You have 1 or more incorrect fields. Please correct them now!"); // let them know that they have inccorect fields
   	return false; // make the onsumbit false
   }

}
ghost_from_sa
Junior Poster in Training
53 posts since May 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

I merged this thread with the duplicate one in the PHP board.

jbennet
Moderator
Team Colleague
18,528 posts since Apr 2005
Reputation Points: 1,826
Solved Threads: 609
Skill Endorsements: 29

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0879 seconds using 2.69MB