Skip to content

sasalatart/uc-number-validator

Repository files navigation

UC Number Validator

Provides a UC Student Number (número de alumno de la Pontificia Universidad Católica de Chile) validation method for a string or a model's attribute.

Credits to Patricio López for his JS implementation.

Gem Version Code Climate Build Status Coverage Status

Installation

Add this line to your application's Gemfile:

gem 'uc_number_validator'

And then execute:

$ bundle

Or install it yourself as:

$ gem install uc_number_validator

Usage

If you want to validate a single string:

require 'uc_number_validator' # Unless working with Ruby on Rails

'1263476J'.valid_uc_number?
=> true
'1263476-J'.valid_uc_number?
=> false

If you want to validate a model attribute you just need to set uc_number: true (like any model validation in Ruby on Rails):

class User < ActiveRecord::Base
  attr_accessor :student_number

  validates :student_number, uc_number: true
end

Contributing

  1. Fork this repository
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'add my feature')
  4. Push to your feature branch (git push origin my-new-feature)
  5. Create a new Pull Request

Releases

No releases published

Packages

No packages published

Languages