isRutLike()
Quick format check to determine if a string looks like a RUT, without validating the verifier digit.
Basic Usage
import { isRutLike } from 'rut.ts'
isRutLike('12.345.678-9') // true
isRutLike('not-a-rut') // falseType Signature
function isRutLike(rut: string): booleanParameters
rut(string) - The string to check
Return Value
Returns boolean:
trueif the string looks like a RUT formatfalseotherwise
Examples
Valid Formats
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
import { isRutLike } from 'rut.ts'
isRutLike('abcdefgh') // false (letters)
isRutLike('') // false (empty)
isRutLike('12.34.56-7') // false (wrong dot pattern)
isRutLike('12,345,678-9') // false (commas not supported)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.
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
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
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
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:
- Only checks format with regex
- Doesn’t calculate verifier digit
- Doesn’t decompose the RUT
Use it for quick filtering before full validation.
Related Functions
validate()- Full validation with verifier checkformat()- Format RUT stringsclean()- Clean RUT strings
Last updated on