Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save RobertoCGarcia/417a1501f7323c5099454cdbeb11001a to your computer and use it in GitHub Desktop.
Save RobertoCGarcia/417a1501f7323c5099454cdbeb11001a to your computer and use it in GitHub Desktop.
Validación de Campos JavaScript Para WebForm de Drupal 8 - Código Probado para agregar una validación via custom js a los campos generados por el módulo webform de Drupal 8.
function validateCaptcha(){
var valueGr = document.getElementById("g-recaptcha-response").value;
if(valueGr == null){
return false;
}else{
return true;
}
}
$(document).ready(function () {
console.log("Entra a validacion de Formulario de Webform");
jQuery("#edit-telefono-cliente").on('input', function (event) {
this.value = this.value.replace(/[^0-9]/g, '');
console.log("Validacion edit-telefono-cliente");
});
jQuery("#edit-telefono-celular-cliente").on('input', function (event) {
this.value = this.value.replace(/[^0-9]/g, '');
console.log("Validacion edit-telefono-celular-cliente");
});
jQuery("#edit-nombre-cliente").on('input', function (event) {
this.value = this.value.replace(/[^a-zA-Z\s]/g, '');
console.log("Validacion edit-nombre-cliente");
});
jQuery("#edit-apellidos-cliente").on('input', function (event) {
this.value = this.value.replace(/[^a-zA-Z\s]/g, '');
console.log("Validacion edit-apellidos-cliente");
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment