Skip to content

Instantly share code, notes, and snippets.

Created July 24, 2010 10:55
Show Gist options
  • Save anonymous/e96077de66bc314d1df2 to your computer and use it in GitHub Desktop.
Save anonymous/e96077de66bc314d1df2 to your computer and use it in GitHub Desktop.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Titre</title>
<script type="text/javascript">
var formulaire,
champDate;
window.onload = function() {
formulaire = document.forms[0];
champDate = formulaire.elements['date'];
formulaire.onsubmit = function() {
var today = new Date();
var expression = new RegExp("^([0-9]{4})-([0-9]{2})-([0-9]{2})$");
if(expression.test(champDate.value)) {
var annee = parseInt(champDate.value.substr(0,4));
var mois = parseInt(champDate.value.substr(5,2) - 1);
var jour = parseInt(champDate.value.substr(8,2));
var date = new Date(annee, mois, jour);
if(today < date) {
return true;
}
alert('La date entrée ne peut pas être égale ou inférieure à celle actuelle.');
return false;
} else {
alert("La date doit être au format AAAA-MM-JJ");
return false;
}
};
};
</script>
</head>
<body>
<form method="post" action="cible.php">
<div>
<label for="date">Entrez une date :</label>
<input type="text" name="date" id="date" value="2010-07-24" />
<input type="submit" value="OK" />
</div>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment