- Return true or false
- Corret Format: NNNNNNNN-V
npm i simple-rut-validator
import { checkRut } from "simple-rut-validator"
const rut = "12098123-k";
const isValid = checkRut(rut); // will return true
const rut = "12.098.123-k";
const isValid = checkRut(rut); // will return false
const rut = "12098123k";
const isValid = checkRut(rut); // will return false
import React, { useState, useEffect } from "react";
import { checkRut } from "simple-rut-validator";
const RegisterForm = () => {
const [rut, setRut] = useState("");
const [validRut, setValidRut] = useState(false);
useEffect(() => {
setValidRut(checkRut(rut));
}, [rut]);
return (
<div>
<input
type="text"
onChange={e => setRut(e.target.value)}
placeholder="19123456-9"
value={rut}
/>
<label>
{validRut
? "Rut ingresado es válido"
: "Ingresa el rut sin puntos y con guión. Ejemplo: 19123456-9"}
</label>
</div>
);
};
export default RegisterForm;