MediaWiki:Agegate.js

/* Based on http://www.webdeveloper.com/forum/showthread.php?253028-Birthday-Validation-mm-dd-yyyy */

function Validateform{ var email=document.form1.email; var firstname=document.form1.firstname; var lastname=document.form1.lastname; var state=document.form1.state; var birthday=document.form1.birthday; var reEmail = /^(?:\w+\.?)*\w+@(?:\w+\.)*\w+$/; var valid = "0123456789/"; var slashcount = 0; if ((email.value==null)||(email.value=="")){ alert("Please enter an email address"); email.focus; return false; }   if (reEmail.test(email.value)==false){ alert ("Please enter a valid email address"); email.focus; return false; }       if ((firstname.value=="")||(firstname.value==null)) { alert("Please enter a first name"); firstname.focus; return false; }   if ((lastname.value=="")||(lastname.value==null)) { alert("Please enter a last name"); lastname.focus; return false; }       if (state.selectedIndex==0 ) { alert("Select state"); state.focus; return false; }   if ((birthday.value=="")||(birthday.value==null)) { alert("This field is required. Please enter date mm/dd/yyyy!") birthday.focus; return false; }    if (birthday.length!=10) { alert("Invalid date! The correct date format is like '01/01/2004'. Please try again.") return false; }

for (var i=0; i < birthday.length; i++) {        temp = "" + birthday.substring(i, i+1); if (temp == "/") slashcount++; if (valid.indexOf(temp) == "-1") { alert("Invalid characters in your date. Please try again.") return false; }        if (slashcount != 2) { alert("Invalid Date! The correct date format is like '01/01/2004'. Please try again.") return false; }        if((birthday.charAt(2)!= '/')||( birthday.charAt(5) != '/')) { alert("Invalid date! The correct date format is like '01/01/2004'. Please try again.") return false } }   return true }

 .style1 { text-align: center; font-size: x-large; } .style2 { text-align: center; } .style3 { text-align: left; } .style4 { text-align: right; } .style5 { text-align: left; margin-left: 160px; }



Add Contact



" method="post" id="form1" name="form1" onsubmit="return Validateform;">

* Required Field  Administrative Area

<?php

} else { // The form has been submitted; process form

include("dl.php");

$email=$_POST['email']; $lastname=$_POST['lastname']; $firstname=$_POST['firstname']; $phone=$_POST['phone']; $address1=$_POST['address1']; $address2=$_POST['address2']; $birthday=$_POST['birthday']; $city=$_POST['city']; $state=$_POST['state']; $zip=$_POST['zip']; $query = "INSERT INTO person (Email, Last_Name,First_Name,phone,address1,address2,birthday,city,state,zip) VALUES ('$email','$lastname','$firstname','$phone','$address1','$address2','$birthday','$city','$state','$zip')";

if (!mysql_query($query,$con)) {      die('Error: ' . mysql_error); } else { echo "  Contact info for $firstname $lastname has been successfully added; If you are 30-60 years old you will receive a middle age discount. If you are 60 or older you will receive a senior citizen discount. Administrative Area "; }

mysql_close;

} ?>