Giter Site home page Giter Site logo

alejandrehl / simple-rut-validator Goto Github PK

View Code? Open in Web Editor NEW
4.0 3.0 1.0 6 KB

Npm module to valid chilean rut :star:

Home Page: https://www.npmjs.com/package/simple-rut-validator

License: MIT License

JavaScript 100.00%
node nodejs chile chilean-rut-utils chilean-rut rut npm npm-package npm-module

simple-rut-validator's Introduction

Simple Rut Validator

  1. Return true or false
  2. Corret Format: NNNNNNNN-V

How to use

  1. npm i simple-rut-validator
  2. 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;

simple-rut-validator's People

Contributors

alejandrehl avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

difuentes

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.