restrictions pour validation de champ
bonjour j'aimerai ajouter quelques restrictions a ma fonction qui valide un champ "email"...
1. l'adresse email doit commencer par a-zA-Z0-9._-
2. au mois 2 caracteres apres le @
3. entre 2 et 4 caracteres apres le dernier point (.com ou .net .org...)
voici le code de ma fonction jusqua maintenant.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| function valemail() {
var str1;
str1 = document.getElementById("email").value;
var acom = str1.indexOf('@')
if(acom == -1){
alert("Email Invalide.")
document.getElementById("email").style.backgroundColor = "#fba";
}else{
alert("Email Valide")
document.getElementById("email").style.backgroundColor = "";
}
} |