36 lines
1.2 KiB
PHP
36 lines
1.2 KiB
PHP
@push('page_scripts')
|
|
<script>
|
|
class Rut {
|
|
static digitoVerificador(rut) {
|
|
if (!(typeof rut === 'string' || rut instanceof String)) {
|
|
rut = rut.toString()
|
|
}
|
|
if (rut.length === 0) {
|
|
return ''
|
|
}
|
|
let M = 0, S = 1
|
|
for (; rut; rut = Math.floor(rut / 10)) {
|
|
S = (S + rut % 10 * (9 - M++ % 6)) % 11
|
|
}
|
|
return S ? S - 1 : 'K'
|
|
}
|
|
static format(rut) {
|
|
if (!(typeof rut === 'string' || rut instanceof String)) {
|
|
rut = rut.toString()
|
|
}
|
|
if (rut.length === 0) {
|
|
return ''
|
|
}
|
|
rut.replace(/\D/g, '')
|
|
return rut.replace(/^(\d{1,2})(\d{3})(\d{3})$/, '$1.$2.$3')
|
|
}
|
|
static validar(rut, digito) {
|
|
if (!(typeof digito === 'string' || digito instanceof String)) {
|
|
digito = digito.toString()
|
|
}
|
|
return Rut.digitoVerificador(rut).toString().toUpperCase() === digito.toUpperCase()
|
|
}
|
|
}
|
|
</script>
|
|
@endpush
|