Code Monkey home page Code Monkey 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.

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

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.