Before generating your application, you will need:
- Ruby ~> 2.0
- Rails ~> 4.0
In your Gemfile
gem 'kangal'
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
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
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
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
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
If you discover any bugs or want to drop a line, feel free to create an issue on GitHub.
http://github.com/lab2023/kangal
Kangal uses TomDoc, rDoc and SemVer, and takes it seriously.
Once you've made your great commits:
- Fork Template
- Create a topic branch -
git checkout -b my_branch
- Push to your branch -
git push origin my_branch
- Create a Pull Request from your branch
- That's it!
- Kangal is maintained and funded by lab2023 - information technologies
- Thank you to all the contributors!
- The names and logos for lab2023 are trademarks of lab2023, inc.
Copyright 2014 lab2023 - information technologies