develop (#45)
Co-authored-by: Juan Pablo Vial <jpvialb@incoviba.cl> Reviewed-on: #45
This commit is contained in:
41
app/resources/views/layout/body/scripts/rut.blade.php
Normal file
41
app/resources/views/layout/body/scripts/rut.blade.php
Normal file
@ -0,0 +1,41 @@
|
||||
@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 clean(rut) {
|
||||
if (!(typeof rut === 'string' || rut instanceof String)) {
|
||||
rut = rut.toString()
|
||||
}
|
||||
return rut.replace(/\D/g, '')
|
||||
}
|
||||
static validar(rut, digito) {
|
||||
if (!(typeof digito === 'string' || digito instanceof String)) {
|
||||
digito = digito.toString()
|
||||
}
|
||||
return Rut.digitoVerificador(rut).toString().toUpperCase() === digito.toUpperCase()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@endpush
|
Reference in New Issue
Block a user