1,105,312 Community Members

Datet of Birth Validation - JS or PHP?

Member Avatar
ghost_from_sa
Junior Poster in Training
53 posts since May 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
sv3tli0
Junior Poster in Training
81 posts since Aug 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 18 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
ghost_from_sa
Junior Poster in Training
53 posts since May 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
sv3tli0
Junior Poster in Training
81 posts since Aug 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 18 [?]
Skill Endorsements: 0 [?]
 
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

Member Avatar
ghost_from_sa
Junior Poster in Training
53 posts since May 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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
   }

}
Member Avatar
jbennet
Moderator
17,127 posts since Apr 2005
Reputation Points: 1,618 [?]
Q&As Helped to Solve: 736 [?]
Skill Endorsements: 38 [?]
Team Colleague
Featured
 
0
 

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

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: