$(document).ready(function () {
    $('#txtTelefono').keyup(function (e) {
        if (!(/\d/g.test(+this.value))) {
            this.value = this.value.replace(/\D/g, '');
        }
    });
    $('#txtNombre').keyup(function (event) {
        if (!/^[a-zA-Z ]*$/gm.test(this.value) || event.key === '_') {
            this.value = this.value.replace(event.key, '');
        }
    });
    $('#txtNombre').blur(function (event) {
        this.value = this.value.trim();
        this.value = Array.from(new Set(this.value.split(" "))).join(' ')
    });
    $('#txtApellidos').keyup(function (event) {
        if (!/^[a-zA-Z ]*$/gm.test(this.value) || event.key === '_') {
            this.value = this.value.replace(event.key, '');
        }
    });
    $('#txtApellidos').blur(function (event) {
        this.value = this.value.trim();
        this.value = Array.from(new Set(this.value.split(" "))).join(' ')
    });
    $('#txtEmpresa').keyup(function (event) {
        if (!/^[a-zA-Z ]*$/gm.test(this.value) || event.key === '_') {
            this.value = this.value.replace(event.key, '');
        }
    });
    $('#txtEmpresa').blur(function (event) {
        this.value = this.value.trim();
        this.value = Array.from(new Set(this.value.split(" "))).join(' ')
    });
});