Skip to content

Instantly share code, notes, and snippets.

@miguelzetina
Created November 1, 2019 04:29
Show Gist options
  • Save miguelzetina/6e0e5523d7f5c67f48293a0f8a4adc52 to your computer and use it in GitHub Desktop.
Save miguelzetina/6e0e5523d7f5c67f48293a0f8a4adc52 to your computer and use it in GitHub Desktop.
window.Parsley.addValidator('uppercase', {
requirementType: 'string',
validateString: function(value, requirement) {
var uppercases = value.match(/[A-Z]/g) || [];
return uppercases.length >= requirement;
},
messages: {
en: 'La contraseña debe tener al menos una letra mayúscula'
}
});
window.Parsley.addValidator('number', {
requirementType: 'number',
validateString: function(value, requirement) {
var numbers = value.match(/[0-9]/g) || [];
return numbers.length >= requirement;
},
messages: {
en: 'La contraseña debe tener al menos un número'
}
});
window.Parsley.addValidator('special', {
requirementType: 'number',
validateString: function(value, requirement) {
var specials = value.match(/[^a-zA-Z0-9]/g) || [];
return specials.length >= requirement;
},
messages: {
en: 'La contraseña debe tener al menos un caracter especial'
}
});
$(document).ready(()=>{
$(".show-hide-password").on("click", e =>{
e.preventDefault();
const current = $(".show-hide-password").attr("action");
if(current == "hide"){
$(".password").attr("type", "text");
$(".show-hide-password").attr("action", "show");
$(".icon").removeClass("fa-eye").addClass("fa-eye-slash");
}
if(current == "show"){
$(".password").attr("type", "password");
$(".show-hide-password").attr("action", "hide");
$(".icon").removeClass("fa-eye-slash").addClass("fa-eye");
}
})
$(".show-hide-confirm-password").on("click", e =>{
e.preventDefault();
var current = $(".show-hide-confirm-password").attr('action');
if(current == "hide"){
$(".confirm-password").attr('type', 'text');
$(".show-hide-confirm-password").attr('action', 'show');
$(".icon2").removeClass("fa-eye").addClass("fa-eye-slash");
}
if(current == 'show'){
$(".confirm-password").attr('type', 'password');
$(".show-hide-confirm-password").attr('action', 'hide');
$(".icon2").removeClass("fa-eye-slash").addClass("fa-eye");
}
})
$("#form-password").submit(function (){
$.ajax({
type: "POST",
url: "/api/parent/new-password",
data: JSON.stringify({token: $.url("?token"), password: $("#form-password input[name=password]").val()}),
dataType: "json",
contentType: "application/json",
success:function(response) {
console.log($.url("?token"));
console.log($("#form-password input[name=password]").val());
console.log("SUCCESS");
console.log(response);
},
error:function(response) {
console.log($.url("?token"));
console.log($("#form-password input[name=password]").val());
console.log($("#password"));
console.log("FAILED");
console.log(response);
}
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment