🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

validator

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

validator

0.1.1
Rubygems
Version published
Maintainers
1
Created
Source

Active Model Validator Travis

This is a ActiveModel validators for domains (including TLDs), ip addresses and email addresses.

Installation

gem install validator

Usage

In your models, the gem provides new validators like :domain, :ip_address or :email

class Model < ActiveRecord::Base
  validates :domain_name, :domain => true
  validates :ip, :ip_address => true
  validates :email_address, :email => true
end

Domain Validator

# validate domain name by full length, label length, TLD existing
validates :domain_name, :domain => true

validates :domain_name, :domain => { :message => 'custom message' }

# custom full domain and label length
validates :domain_name, :domain => { :length => 200, :label_length => 60 }

# skip TLD validation
validates :domain_name, :domain => { :check_tld => false }

Ip Address Validator

# validate ip address
validates :ip, :ip_address => true

# ip address allowed with prefix
validates :ip, :ip_address => { :allow_prefix => true }

# allows only IPv4
validates :ip, :ip_address => { :only => :ipv4 }

# allows only IPv6
validates :ip, :ip_address => { :only => :ipv6 }

validates :ip, :ip_address => { :message => "custom message" }

Email Address Validator

validates :email_address, :email => true

validates :email_address, :email => { :message => 'custom message' }

# custom local part, full domain and label length of email address
validates :email_address, :email => { :local_length => 60, :domain => { :length => 200, :label_length => 60 }}

Localization Tricks

To customize error message, you can use { :message => "your custom message" } or simple use Rails localization en.yml file, for instance:

en:
  errors:
    messages:
      domain:
        length: "your custom length error message"
     ip_address:
       invalid:
         general: "your custom invalid ip address error message"
  activemodel:
    errors:
      messages:
        domain:
          invalid: "custom error message only for activemodel"
       models:
         your_model:
           domain:
             invalid: "custom error message for YourDomain model"

Copyright (c) 2011 Vitaliy Nahaylo. See LICENSE for details.

FAQs

Package last updated on 28 Feb 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts