GithubHelp home page GithubHelp logo

angular-rut's Introduction

angular-rut Bower version Build Status

An Angular module with several components to handle Chilean RUT validation, cleaning and formatting. It includes:

  • ngRut: a directive to easily add validation, cleaning and formatting to any element with an associated ng-model value
  • rut: a filter to format valid RUTs with dots and dashes (11.111.111-1) in the view
  • RutHelper: a constant you can inject in your modules and exposes individual methods for validation, cleaning and formatting.

angular-rut is no longer maintained.

  • We will leave the Issues open as a discussion forum only.
  • We do not guarantee a response from us in the Issues.
  • We are no longer accepting pull requests.

Installation

Just use Bower.

bower install angular-rut --save

Then, inject it into your application:

angular.module('MyApp', ['platanus.rut']);

Directive

Add the ng-rut directive to any element with an associated ng-model to automatically perform validation, cleaning and formatting.

<input ng-rut type="text" ng-model="model.rut">

The directive does the following:

  • It validates whether the input is a valid RUT (by using $setValidity),
  • passes a clean RUT (numbers and K only) to the model,
  • and formats the view by adding dots and dashes (11.111.111-1).

Options

You can use the rut-format attribute to define when should the view be formatted:

  • live: Format as the RUT changes (e.g. as a user types into the input):
<input ng-rut rut-format="live" type="text">
  • blur: Format when the input is blurred:
<input ng-rut rut-format="blur" type="text">

Filter

Use it just like any Angular filter. It takes a (presumably valid) RUT, cleans and formats it.

{{ model.rut | rut }} 

RutHelper

Inject it as a dependency anywhere you like:

app.controller('RutCtrl', ['RutHelper', function(RutHelper){ ...

Then use it like so:

RutHelper.format('111111111'); // returns 11.111.111-1

There are three methods available:

  • RutHelper.clean(rut) strips every character except numbers and the letter K.
  • RutHelper.format(rut) cleans and formats the RUT number with dots and dashes (e.g 11.111.111-1).
  • RutHelper.validate(rut) returns a boolean indicating whether the given RUT is valid.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Credits

Thank you contributors!

Platanus

angular-rut is maintained by platanus.

License

It is free software and may be redistributed under the terms specified in the LICENSE file.

angular-rut's People

Contributors

agustinf avatar antidiestro avatar blackjid avatar bunzli avatar gmq avatar iobaixas avatar ldlsegovia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

angular-rut's Issues

Versión 1.0?

@bunzli y @ReneMoraales, que opinan? creo que nos deberíamos casar con la interfaz actual y decir que es la versión 1.0.

Validación aprueba rut no válido

Estimados,
Al ingresar "1.727.k17-2" es marcado como un RUT válido, cuando no lo es.

El markup que utilizo es el siguiente

<input ng-rut type="text" ng-model="ctrl.client.Rut" md-no-asterisk name="rut" ng-maxlength="13" required>

La versión de angular-rut usada es la 1.0.1.

Teclado se cambia de modo en Android

En algunos dispositivos, no en todos, depende del teclado de SO. Cuando se ocupa el modo live el teclado se cambia de la capa numerica a la texto
Esto pasa por que cuando se formatea el rut en el input se agrega el . (punto) de la separacion de miles y este carácter se encuentra en el teclado inicial (letras).

Teclados de Letras y Numericos

teclado letras y numerico

La solución puede ser usar el modo blur, pero de esta manera se permiten ingresar caracteres no deseados ([a-z!"·$%&/()=?¿]).

Caso (Sony Xperia Z1, Android 5.1.1)
ezgif com-optimize

Lo ideal seria tener una opcion para reemplazar siempre los caracteres no deseados y solo dejar ingresar numeros y la letra K

Saludos

Digito verificador en input aparte

Han visto que a veces las páginas separan el rut en dos inputs, el "cuerpo" y el digito verificador. Debiéramos hacer algo para soportar eso

<input ng-rut-body rut-format="live" ng-model="data.rutBody" type="text">
-
<input ng-rut-digit  rut-body="data.rutBody" ng-model="data.rutDigit" type="text">

Algo así....

Exception on empty input

Validator is throwing an exception every time the bound input is cleared, it appears that the ngmodel passes undefined to the parsers when input is empty.

Validacion de formato mientras se valida en modo live

En modo live se permite ingresar formatos invalidos de rut, ej: 1k2k3k4k5
Sugiero tambien validar el valor contra la expresion regular del rut (^\d{1,3}(.?\d{3})*-?[Kk|\d]{1}$) a medida que se ingresan datos para evitar cosas como la mencionada anteriormente.

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.