Low commit activity in last 3 years
A long-lived project that still receives updates
Taiwanese Id Validator
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0
>= 2.2.33

Runtime

 Project Readme

Taiwanese Id Validator for Ruby on Rails

CircleCI

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

Features

  • Rails model 內驗證 (Rails 3+/4/5/6/7)
  • 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") #=> 女性的身分證字號

驗證統一證號

ItidValidator.valid?('A800000014') #=> true
ItidValidator.valid?('A800000015') #=> false

Others

Contributing

Check DEVELOPMENT.md

LICENSE

This project rocks and uses MIT-LICENSE.