Skip to content
Extended validation gem for email, subdomain, credit card, tax number etc...
Branch: develop
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
config/locales
lib
spec
.gitignore
.travis.yml
CHANGELOG.md
Gemfile
LICENSE.txt
README.md
Rakefile
SECURITY.md
kangal.gemspec

README.md

Kangal

Code Climate Dependency Status Build Status

Requirements

Before generating your application, you will need:

  • Ruby ~> 2.0
  • Rails ~> 4.0

Usage

In your Gemfile

gem 'kangal'

Email Validator

require 'kangal'
class User
  include ActiveModel::Validations
  attr_accessor :email

  # Email validator
  validates :email, presence: :true, email: :true
end


p = User.new
p.email = "info@lab2023.com"
p.valid? # => true

p.email = "info@lab"
p.valid? # => false

p.email = "Onur Ozgur <info@lab2023.com>"
p.valid? # => false

Subdomain Validator

require 'kangal'
class User
  include ActiveModel::Validations
  attr_accessor :subdomain

  # Subdomain validator
  validates  :subdomain, subdomain: true

  # Or
  validates  :subdomain, subdomain: { :reserved => %w(foo bar) }
end


p = User.new
p.subdomain = "www"
p.valid? # => false

p.subdomain = "https"
p.valid? # => false

p.subdomain = "-lab2023"
p.valid? # => false

p.subdomain = "-lab2023-"
p.valid? # => false

p.subdomain = "foo"
p.valid? # => false

p.subdomain = "lab2023"
p.valid? # => true

Default reserved names: www, ftp, mail, pop, smtp, admin, ssl, sftp, http, https

Turkish Government Identity Number Validator

require 'kangal'
class User
  include ActiveModel::Validations
  attr_accessor :identity

  # Identity Number validator
  validates :identity, presence: :true, identity_number: :true
end

p = User.new
p.identity = "44234234"
p.valid? # => false

p = User.new
p.identity = "02343214582"
p.valid? # => false

p = User.new
p.identity = "83317527040" # (this isn't a real identity number)
p.valid? # => true

Turkish Government Tax Number Validator

require 'kangal'
class User
  include ActiveModel::Validations
  attr_accessor :tax_number

  # Identity Number validator
  validates :tax_number, presence: :true, tcvkn: :true
end

p = User.new
p.tax_number = "44234234"
p.valid? # => false

p = User.new
p.tax_number = "02343214582"
p.valid? # => false

p = User.new
p.tax_number = "6120069217" # (this isn't a real tax number)
p.valid? # => true

IP Validator

require 'kangal'
class Server
  include ActiveModel::Validations
  attr_accessor :ip

  # Ip validator
  validates :ip, presence: :true, ip: :true
end

p = Server.new
p.ip = "10.10.10.256"
p.valid? # => false

p = Server.new
p.ip = "2222.22.22.22"
p.valid? # => false

p = Server.new
p.ip = "255.255.255.255"
p.valid? # => true

p = Server.new
p.ip = "132.254.111.10"
p.valid? # => true

Bugs and Feedback

If you discover any bugs or want to drop a line, feel free to create an issue on GitHub.

http://github.com/lab2023/kangal

Contributing

Kangal uses TomDoc, rDoc and SemVer, and takes it seriously.

Once you've made your great commits:

  1. Fork Template
  2. Create a topic branch - git checkout -b my_branch
  3. Push to your branch - git push origin my_branch
  4. Create a Pull Request from your branch
  5. That's it!

Credits

lab2023

License

Copyright 2014 lab2023 - information technologies

You can’t perform that action at this time.