chilerut

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 3 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

Valid is permissive and normalizes common separators. Use ValidStrict at API or form boundaries when arbitrary characters must be rejected:

chilerut.ValidStrict("12.667.869-K") // true
chilerut.ValidStrict("12667869K")     // true
chilerut.ValidStrict("12*667*869*K")  // false
Input rules
  • Valid is permissive: it normalizes common separators and ignores other non-significant characters for compatibility.
  • ValidStrict accepts only compact (12667869K), hyphenated (12667869-K), or conventionally dotted (12.667.869-K) input. It trims outer whitespace, accepts lowercase k, and rejects malformed separators, all-zero bodies, and lone verification digits.
  • Format, Compact, and FormatWithDots normalize input but do not verify the verification digit. Use Valid or ValidStrict when validity matters.
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"
Compact and display formats
chilerut.Compact("12.667.869-k")      // "12667869K"
chilerut.FormatWithDots("12667869K")  // "12.667.869-K"

Compact always includes the final significant character as the verification digit. All-zero input normalizes to an empty string.

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 Compact added in v1.1.0

func Compact(rut string) string

Compact returns a normalized RUT without separators, including its verification digit (e.g. "12667869K").

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 FormatWithDots added in v1.1.0

func FormatWithDots(rut string) string

FormatWithDots returns the conventional Chilean display form of a RUT (e.g. "12.667.869-K").

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 ValidStrict added in v1.1.0

func ValidStrict(rut string) bool

ValidStrict reports whether rut uses an accepted RUT syntax and has a valid modulo 11 verification digit.

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