isRutLike()
Quick bounded format check to determine if a value looks like a RUT, without validating the verifier digit.
Basic Usage#
TypeScript
import { isRutLike } from 'rut.ts'
isRutLike('12.345.678-9') // true
isRutLike('not-a-rut') // falseType Signature#
TypeScript
function isRutLike(rut: unknown): booleanParameters#
rut(unknown) - The value to check
Return Value#
Returns boolean:
trueif the string looks like a RUT formatfalseotherwise
Examples#
Valid Formats#
TypeScript
import { isRutLike } from 'rut.ts'
// All RUT-like formats
isRutLike('12.345.678-9') // true (standard format)
isRutLike('12345678-9') // true (no dots)
isRutLike('123456789') // true (no formatting)
isRutLike('1.234.567-K') // true (7-digit body)
isRutLike('09.068.826-K') // true (leading zeros)Invalid Formats#
TypeScript
import { isRutLike } from 'rut.ts'
isRutLike('abcdefgh') // false (letters)
isRutLike('') // false (empty)
isRutLike('12.34.56-7') // false (wrong dot pattern)
isRutLike('12.345678-9') // false (ambiguous dot grouping)
isRutLike('12,345,678-9') // false (commas not supported)
isRutLike(123456789) // false (not a string)Difference from validate()#
isRutLike() only checks if the format looks correct. It does NOT validate the verifier digit. Use
validate() for full validation including verifier digit check.
TypeScript
import { isRutLike, validate } from 'rut.ts'
const rut = '12.345.678-0' // Wrong verifier (should be 5)
isRutLike(rut) // true ✅ (format is correct)
validate(rut) // false ❌ (verifier is wrong)Use Cases#
Early Form Validation#
TypeScript
import { isRutLike } from 'rut.ts'
function handleInput(value: string) {
if (!isRutLike(value)) {
showError('Please enter a valid RUT format')
return
}
// Continue with full validation
if (validate(value)) {
saveRut(value)
}
}Filter Lists#
TypeScript
import { isRutLike } from 'rut.ts'
const inputs = ['12.345.678-5', 'invalid', '18.972.631-7', 'abc', '9068826K']
// Quick filter for RUT-like strings
const potentialRuts = inputs.filter(isRutLike)
console.log(potentialRuts)
// ['12.345.678-5', '18.972.631-7', '9068826K']Pre-validation Check#
TypeScript
import { isRutLike, validate } from 'rut.ts'
function validateRut(input: unknown): boolean {
// Quick type/format check first
if (typeof input !== 'string' || !isRutLike(input)) {
return false
}
// Then do full validation (more expensive)
return validate(input)
}Performance#
isRutLike() is faster than validate() because:
- It checks type, length, and accepted RUT shapes first
- It does not calculate the verifier digit
- It rejects oversized input before running the shape checks
Use it for quick filtering before full validation.
Related Functions#
validate()- Full validation with verifier checkformat()- Format RUT stringsclean()- Clean RUT strings