GithubHelp home page GithubHelp logo

wangkesen / taiwanese_id_validator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wayne5540/taiwanese_id_validator

0.0 2.0 0.0 15 KB

台灣身分證字號 驗證&產生 的 Gem

License: MIT License

Ruby 100.00%

taiwanese_id_validator's Introduction

Taiwanese Id Validator for Ruby on Rails

Build Status

台灣身分證字號 驗證&產生 的 Gem

Features

  • Rails model 內驗證 (Rails 3+/4)
  • Rails model 外驗證
  • 產生符合格式的身分證字號,可選擇男女

Installation

Add this line to your application's Gemfile:

gem 'taiwanese_id_validator'

And then execute:

$ bundle

Or install it yourself as:

$ gem install taiwanese_id_validator

Usage

Rails Model Validation

基本使用

class User < ActiveRecord::Base
  validates :twid, taiwanese_id: true
end

Options

  • allow_nil or allow_blank
class User < ActiveRecord::Base
  validates :twid, taiwanese_id: { allow_nil: true }
end
  • Case sensitive, default is true
class User < ActiveRecord::Base
  validates :twid, taiwanese_id: { case_sensitive: false }
end

Validation outside the model

驗證身分證字號

TwidValidator.valid?('A123456789') #=> true
TwidValidator.valid?('A123456777') #=> false

產生假身分證字號

Generator 是沒有被自動 require 的,所以要使用前要先 require:

require 'taiwanese_id_validator/twid_generator'

TwidGenerator.generate #=> 隨機產生身分證字號

可以指定要產生男性或是女性的身分證字號

TwidGenerator.generate("male") #=> 男性的身分證字號
TwidGenerator.generate("female") #=> 女性的身分證字號

Others

公式

Contributing

  1. Fork it ( https://github.com/[my-github-username]/taiwanese_id_validator/fork )
  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 a new Pull Request

LICENSE

This project rocks and uses MIT-LICENSE.

taiwanese_id_validator's People

Contributors

wayne5540 avatar

Watchers

James Cloos avatar 王可森 avatar

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.