2024-06-18
This commit is contained in:
26
app/resources/views/layout/body/scripts/rut.blade.php
Normal file
26
app/resources/views/layout/body/scripts/rut.blade.php
Normal file
@ -0,0 +1,26 @@
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
class Rut {
|
||||
static digitoVerificador(rut) {
|
||||
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 (rut.length === 0) {
|
||||
return ''
|
||||
}
|
||||
rut.replace(/\./g, '')
|
||||
return rut.replace(/^(\d{1,2})(\d{3})(\d{3})$/, '$1.$2.$3')
|
||||
}
|
||||
static validar(rut, digito) {
|
||||
return Rut.digitoVerificador(rut) === digito
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@endpush
|
Reference in New Issue
Block a user