Hey all! I'm having a few problems with this script:

- the third text input in the form is requesting for the user's favorite color. I need it to validate the data to either be a defined color or a hexadecimal value and then turn the background into that color upon submission. However, it's not validating correctly... When a correct value is entered it works fine, it's the error message for an invalid entry that's not appearing.

- I need to save all of the user's input into a cookie which will automatically load their preferences the next time they visit the site(time of day message, first & last name and bg color).

Ideas?

Here's what I have so far:

Code:
<html>
<head>
<script language="javascript">

<!-- Début

//Valider formulaire
function valider(){

if (document.testform.Prenom.value=="") {
alert("S.V.P. indiquez votre prénom!")
return false;
}
if (document.testform.Nom.value=="") {
alert("S.V.P. indiquez votre nom de famille!")
return false;
}
if (document.testform.Couleur.value=="") {
alert("S.V.P. indiquez votre couleur préféré!")
return false;
}

var inputField = document.getElementById("Couleur").value.substr(1);
if (!/^[a-f0-9]{3}$|^[a-f0-9]{6}$/i.test(inputField))
{
	alert("Vous devez indiquez une valeur hexidécimale ou une couleur définie!");
return false;
}
return true;
}

//Change la couleur d'arrière plan
function changeBg(){
  var PrNom = document.forms[0].Prenom.value;
  var NomF = document.forms[0].Nom.value;
  var bgColor = document.testform.Couleur.value;
  
  //Message de bienvenue en fonction de l'heure
  var heure=new Date().getHours()
  var msg=""
  if (heure<=6) {msg="Bonne nuit"}
  if (heure>6 && heure<=12) {msg="Bon matin"}
  if (heure>12 && heure<=18) {msg="Bonne après-midi"}
  if (heure>18 && heure<=24) {msg="Bonne soirée"}

  document.write(msg +" " +PrNom +" " +NomF +"!");
  document.bgColor = bgColor;
 }

// Fin -->
</SCRIPT>
</head>
<body>

<form name="testform" onSubmit="changeBg()" />
<br />
Pr&eacute;nom?&nbsp;<input type="text" size=30 name="Prenom"  value="Visiteur" onBlur="valider()"<br />
Nom?&nbsp;<input type="text" size=30 name="Nom" value="Inconnu" onBlur="valider()" /><br />
Couleur pr&eacute;f&eacute;r&eacute;?&nbsp;<input type="text" size=30 name="Couleur" value="#FFFFFF" onBlur="valider()" maxlength="7" /></br />
<input type="submit" value="Valider">
</form>
</body>
</html>