simple-rut-validator
v1.0.1
Published
simple-rut-validator
Downloads
42
Maintainers
Readme
Simple Rut Validator
- Return true or false
- Corret Format: NNNNNNNN-V
How to use
npm i simple-rut-validator
import { checkRut } from "simple-rut-validator"
Basic Example
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
React Example
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;