chilerut

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 28, 2026 License: MIT Imports: 2 Imported by: 0

README

chilerut

CI codecov PkgGoDev

Go package to validate, format and compare Chilean RUTs. Zero dependencies, 100% test coverage, fuzz-tested.

Installation

go get github.com/pzentenoe/chilerut

Requires Go 1.18+.

Usage

import "github.com/pzentenoe/chilerut"
Validate RUT
chilerut.Valid("12345678-9")   // false
chilerut.Valid("6265837-1")    // true

// It works with the following formats:
chilerut.Valid("98685030")     // true
chilerut.Valid("9868503-0")    // true
chilerut.Valid("9.868.503-0")  // true
chilerut.Valid("12-667-869-K") // true
chilerut.Valid("12*667*869-k") // true
Get verification digit
chilerut.VerificationDigit("9868503")  // "0"
chilerut.VerificationDigit("12667869") // "K"
chilerut.VerificationDigit("16647869") // "3"
Format RUT
chilerut.Format("12.667.869.k")        // "12667869-K"
chilerut.Format("12-667-869-k")        // "12667869-K"
chilerut.Format("12*667*869*K")        // "12667869-K"
chilerut.Format("12 667 869 k")        // "12667869-K"
chilerut.Format("12667869k")           // "12667869-K"
chilerut.Format("   000012667869k   ") // "12667869-K"
Compare RUT
chilerut.Compare("12667869k", "12.667.869-K")    // true
chilerut.Compare("12667869-k", "12.667.869-K")   // true
chilerut.Compare("12.667.861-K", "12.667.869-K") // false

Documentation

Overview

Package chilerut validates, formats and compares Chilean RUT (Rol Único Tributario) numbers using the standard módulo 11 check-digit algorithm.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compare

func Compare(rut1, rut2 string) bool

Compare reports whether two RUTs are the same, ignoring format differences.

func Format

func Format(rut string) string

Format returns the canonical "body-dv" form of a RUT (e.g. "12667869-K"), dropping any separators, leading zeros and lowercasing.

func Valid

func Valid(rut string) bool

Valid reports whether rut is a valid RUT by recomputing its módulo 11 check digit. Any common separator format is accepted.

func VerificationDigit

func VerificationDigit(rut string) string

VerificationDigit computes the expected módulo 11 check digit ("0"-"9" or "K") for the given RUT body.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL