From f831a1a5ed312005f53bffadf0c47ce84a878ef7 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Wed, 9 Dec 2015 12:28:04 +0100 Subject: [PATCH] =?UTF-8?q?Validation=20du=20num=C3=A9ro=20de=20SECU=20ave?= =?UTF-8?q?c=20la=20cl=C3=A9=20de=20contr=C3=B4le?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Consultations.php | 2 +- css/global.css | 16 ++++++++++++++++ js/consultations.js | 38 +++++++++++++++++++++++++++++++++----- 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/Consultations.php b/Consultations.php index 8076b93..173eb5e 100755 --- a/Consultations.php +++ b/Consultations.php @@ -80,7 +80,7 @@ if(!Authentification::checkUser(0)){
- + Numéro invalide.
diff --git a/css/global.css b/css/global.css index 6f114f6..b51825c 100755 --- a/css/global.css +++ b/css/global.css @@ -352,6 +352,22 @@ body{ border-color: #1cc952; } +/* .invalid */ +#CONTAINER > article input.invalid{ + border-color: #ec111c; +} + +/* après */ +#CONTAINER > article input.invalid + span.invalid{ + color: #ec111c; +} + +/* après */ +#CONTAINER > article input:not(.invalid) + span.invalid{ + display: none; + color: #ec111c; +} + /* [type=submit] */ #CONTAINER > article input[type=submit]{ diff --git a/js/consultations.js b/js/consultations.js index 626402e..dca135d 100755 --- a/js/consultations.js +++ b/js/consultations.js @@ -53,7 +53,7 @@ var timeFormat = new formatChecker(null, // format numéro SECU simplifié var secuFormat = new formatChecker(null, - 'S ii ii ii iii iii ii', { 'S': '[0-1]' } + 'S ii Mi ii iii iii ii', { 'S': '[0-1]', 'M': '[0-1]' } ); @@ -84,16 +84,44 @@ inHeure.addEventListener('keyup', function(e){ } }, false); +function checkSecuControlKey(pNumSecu){ + var NIR = pNumSecu.slice(0,-2).replace(/ /g, ''); + var key = pNumSecu.slice(-2); + + return 97-(NIR%97) == key; +} + inSecu.addEventListener('keyup', function(e){ - if( inCk.check(inSecu) ) addClass(inSecu, 'validated'); // on active la classe - else{ // si incorrect + if( inCk.check(inSecu) ){ + + if( checkSecuControlKey(inSecu.value) ){ // si la clé est correcte + addClass(inSecu, 'validated'); // on dis que le champ est valide + remClass(inSecu, 'invalid'); // on dis qu'il n'est pas invalide + }else{ + remClass(inSecu, 'validated'); // on dis que le champ n'est pas valide + addClass(inSecu, 'invalid'); // on dis qu'il est invalide + } + + }else{ // si incorrect + remClass(inSecu, 'validated'); // on désactive la classe + remClass(inSecu, 'invalid'); // on dis qu'il n'est pas invalide + inCk.correct(inSecu, false); // on corrige partiellement - if( inCk.check(inSecu) ) addClass(inSecu, 'validated'); // mise à jour de la classe après correction + if( inCk.check(inSecu) ){ + + if( checkSecuControlKey(inSecu.value) ){ // si la clé est correcte + addClass(inSecu, 'validated'); // on dis que le champ est valide + remClass(inSecu, 'invalid'); // on dis qu'il n'est pas invalide + }else{ + remClass(inSecu, 'validated'); // on dis que le champ n'est pas valide + addClass(inSecu, 'invalid'); // on dis qu'il est invalide + } + } } }, false); // inDate.value = 'x3 F3/a8'; // inHeure.value = 'x3 F3/a8'; -// inSecu.value = 'x3 F3/a8'; \ No newline at end of file +inSecu.value = '1 96 01 31 555 861'; \ No newline at end of file