Sha256: e09719b0f153434c67ec68d19408cfa9877771f15478c69f0792c68b4ffe16fd

Contents?: true

Size: 529 Bytes

Versions: 4

Compression:

Stored size: 529 Bytes

Contents

module OmgValidator
  module Validators
    # Checks whether input is a valid number
    #
    # validates :count, number: true
    class NumericValidator < ActiveModel::EachValidator
      def validate_each(record, attribute, value)
        return nil if value.nil?
        reg = /^[\-+]?[0-9]*\.?[0-9]+$/
        unless reg.match(value)
          record.errors[attribute] = "must be a valid number"
        end
      end
    end
  end
end

ActiveModel::Validations::NumericValidator = OmgValidator::Validators::NumericValidator

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
omg_validator-0.0.6.2 lib/omg_validator/validators/numeric_validator.rb
omg_validator-0.0.6.1 lib/omg_validator/validators/numeric_validator.rb
omg_validator-0.0.6 lib/omg_validator/validators/numeric_validator.rb
omg_validator-0.0.5 lib/omg_validator/validators/numeric_validator.rb