You are on page 1of 5

STI

Classe : Bac Sciences de l’informatique

Correction

(Exercice 1)

---------------------------------

S
Exercice 1 60 min

Inscription.html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Exercice 1</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" type="text/css" media="screen"href="mesStyles.css"/>
<script src="controls.js"></script>
</head>
<body>
<form onsubmit="return verif()">
<fieldset>
<legend>Inscription</legend>
<label for="cin">CIN :</label>
<input type="text" name="cin" id="cin" /><br />
<label for="permis">Num Permis :</label>
<input type="text" name="permis" id="permis" /><br />
<label for="nom">Nom:</label>
<input type="text" name="nom" id="nom" /><br />
<label for="prenom">Prénom :</label>
<input type="text" name="prenom" id="prenom" /><br />
<label for="date">Date de naissance :</label>
<input type="date" name="date" id="date" /><br />

<label>Genre:</label>
<input type="radio" name="genre" id="f" /> Feminin
<input type="radio" name="genre" id="m" /> Masculin
<br />
<label for="mp">Mot de passe :</label>
<input type="password" name="mp" id="mp" />
<label for="cpm" id="l1">Confirmer mot de passe :</label>
<input type="password" name="cpm" id="cpm" />

<div>
<input type="submit" value="Confirmer" />
<input type="reset" value="Annuler" />
</div>
</fieldset>
</form>
</body>
</html>

1
mesStyles.css

form {
width: 800px;
margin: auto;
background-color: azure;
}
label {
display: inline-block;
width: 150px;
margin-top: 20px;
font-family: "Lucida Sans";
}
#l1{ width: 200px; }
input[type="submit"],input[type="reset"] {
display: inline-block;
width: 100px;
margin-top: 20px;
}
div {
width: 220px;
margin: auto;
}

controls.js

function alphabetique(ch)
{
let l=ch.length;
let i=0;
while((i<l)&& (ch.charAt(i).toUpperCase()>='A') &&(ch.charAt(i).toUpperCase()<='Z') )
i++ ;

return (i==l)
}
function chiffres(ch)
{
let l=ch.length;
let i=0;
while((i<l)&& (ch.charAt(i)>='0') &&(ch.charAt(i)<='9') )
i++

return (i==l);
}

2
function NbMajus(ch)
{
let nb=0;
for(let i=0;i<ch.length;i++)
if((ch.charAt(i)>="A") &&(ch.charAt(i)<="Z"))
nb++
return nb;
}
function verif()
{
let cin=document.getElementById("cin").value;
let permis=document.getElementById("permis").value;
let nom=document.getElementById("nom").value;
let prenom=document.getElementById("prenom").value;
let date=document.getElementById("date").value;
let femme=document.getElementById("f").checked;
let homme=document.getElementById("m").checked;
let mp=document.getElementById("mp").value;
let cpm=document.getElementById("cpm").value;

if((cin.length!=8)||(chiffres(cin)))
{
alert("CIN invalide!!!");
return false;
}

let p=permis.indexOf('/');
if((permis.length!=8)||(p!=2))
{
alert("Numero de permis invalide!!!");
return false;
}
let ch1=permis.substr(0,2);
let ch2=permis.substr(3);
if(chiffres(ch1)||chiffres(ch2))
{
alert("Numero de permis invalide");
return false;
}

3
if((alphabetique(nom)==false)|| (nom.length<3) || (nom.length>20))
{
alert("Le Nom doit etre alphabétique est de longueur entre 3 et 20 !!!");
return false;
}

if((alphabetique(prenom)==false)|| (prenom.length<3) || (prenom.length>20))


{
alert("le Prenom doit etre alphabétique est de longueur entre 3 et 20 !!!");
return false;
}
if(date=="")
{
alert("Saisir une date de naissance ");
return false;
}

let dn=new Date(date);


let annee=dn.getFullYear(dn);
if(annee<2000)
{
alert("L’ année de naissance doit être supérieur à 2000!!!");
return false ;
}

if(femme==homme)
{
alert("Choisir un genre !!!");
return false;
}
if(NbMajus(mp)==0)
{
alert("Le mot de passe doit contenir au moins une lettre majuscule!!!");
return false ;
}

if(mp!=cpm)
{
alert("Confirmer le mot de passe !!!!!!");
return false ;
}

You might also like