1.11M Members

Datet of Birth Validation - JS or PHP?

 
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

 
0
 

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

 
0
 

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

 
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

 
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
   }

}
 
0
 

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

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