datePatern & input change

This commit is contained in:
adri 2019-01-02 11:28:58 +01:00
parent a345a22565
commit 08153b67e3
1 changed files with 23 additions and 8 deletions

View File

@ -1,7 +1,7 @@
htmlAddUser = '<tr class="newRecord">\ htmlAddUser = '<tr class="newRecord">\
<td class="login">\ <td class="login">\
<input type="text" /></td>\ <input type="text" /></td>\
<td class="datene">\ <td class="datene" placeholder="yyyy/mm/dd">\
<input type="date" /></td>\ <input type="date" /></td>\
<td class="email">\ <td class="email">\
<input type="text" /></td>\ <input type="text" /></td>\
@ -18,10 +18,13 @@ htmlAddUser = '<tr class="newRecord">\
passwordPatern = /^[a-zA-Z0-9]{8,16}$/; passwordPatern = /^[a-zA-Z0-9]{8,16}$/;
loginPatern = /^[a-z]{8,16}$/ loginPatern = /^[a-z]{8,16}$/
mailPatern = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; //https://emailregex.com/ mailPatern = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; //https://emailregex.com/
datePatern = /^\d{4}[\/\-](?:\d{1}|1[012]|0\d)[\/\-](?:\d{1}|[123]\d|0\d)/
$(function() { $(function() {
$("#allRecord").on("keyup", ".pw input", function() { /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*~~~~~~~~~~~~~~~~INPUT EVENT~~~~~~~~~~~~~~~~*/
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
$("#allRecord").on("keyup change", ".pw input", function() {
if (passwordPatern.test($(this).val()) || $(this).val() == "") { if (passwordPatern.test($(this).val()) || $(this).val() == "") {
$(this).css("background-color", ""); $(this).css("background-color", "");
$('div', $(this).parent()).css("display", "none"); $('div', $(this).parent()).css("display", "none");
@ -30,7 +33,7 @@ $(function() {
$('div', $(this).parent()).css("display", "block"); $('div', $(this).parent()).css("display", "block");
} }
}); });
$("#allRecord").on("keyup", ".email input", function() { $("#allRecord").on("keyup change", ".email input", function() {
if (mailPatern.test($(this).val())) { if (mailPatern.test($(this).val())) {
$(this).css("background-color", ""); $(this).css("background-color", "");
$('div', $(this).parent()).css("display", "none"); $('div', $(this).parent()).css("display", "none");
@ -39,6 +42,16 @@ $(function() {
$('div', $(this).parent()).css("display", "block"); $('div', $(this).parent()).css("display", "block");
} }
}); });
$("#allRecord").on("keyup change", ".datene :input", function(e) {
console.log(e.target.value);
if (datePatern.test($(this).val())) {
$(this).css("background-color", "");
$('div', $(this).parent()).css("display", "none");
} else {
$(this).css("background-color", "red");
$('div', $(this).parent()).css("display", "block");
}
});
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*~~~~~~~~~~~~~~~~TR TO DEL~~~~~~~~~~~~~~~~*/ /*~~~~~~~~~~~~~~~~TR TO DEL~~~~~~~~~~~~~~~~*/
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
@ -119,7 +132,7 @@ $(function() {
if (className == "pw") if (className == "pw")
inputOptions += 'type="password" data-oldpw="' + ltrim(j.html()) + '" '; inputOptions += 'type="password" data-oldpw="' + ltrim(j.html()) + '" ';
else if (j.attr('class') == "datene") else if (j.attr('class') == "datene")
inputOptions += 'type="date" ' inputOptions += 'type="date" placeholder="yyyy/mm/dd"'
j.html('<input ' + inputOptions + ' value="' + (j.attr('class') == "pw" ? '' : ltrim(j.html())) + '" />'); j.html('<input ' + inputOptions + ' value="' + (j.attr('class') == "pw" ? '' : ltrim(j.html())) + '" />');
if (className == "pw") { if (className == "pw") {
j.append("<div>le mot de passe comporte entre 8 et 16 caractères parmi a..z A..Z 0..9</div>") j.append("<div>le mot de passe comporte entre 8 et 16 caractères parmi a..z A..Z 0..9</div>")
@ -137,7 +150,7 @@ $(function() {
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function callBackVerif(data) { function callBackVerif(data) {
var dataToSend = new Object(); //Objet contenant les données à envoyé var dataToSend = new Object(); //Objet contenant les données à envoyé
dataToSend["updatePW"] = (data === true ? false : true); dataToSend["updatePW"] = (data === true ? false : true); //Si maj du mdp data === false
if ($(".pw input", tr).val() === data || data === true) //Verif du mot de passe si nécesaire if ($(".pw input", tr).val() === data || data === true) //Verif du mot de passe si nécesaire
{ {
for (i = 0; i < tds.length - 1; i++) //Analyse de chaque td for (i = 0; i < tds.length - 1; i++) //Analyse de chaque td
@ -218,9 +231,11 @@ $(function() {
}); });
}); });
//J'avais plein d'espace a droite en récupérent mon innerHTML //J'avais plein d'espace à droite et à gauche en récupérent mon innerHTML
//https://stackoverflow.com/questions/24282158/removing-the-white-space-at-the-start-of-the-string //https://stackoverflow.com/questions/24282158/removing-the-white-space-at-the-start-of-the-string
function ltrim(str) { function ltrim(str) {
if (str == null) return str; if (str == null) return str;
return str.replace(/^\s+/g, ''); str = str.replace(/^\s+/g, '')
str = str.replace(/\s+$/g, '')
return str;
} }