Sha256: 10c90272e790f2ac48b782a999fdaa915186d5c7c2830d2dd66d362eeab1df53
Contents?: true
Size: 585 Bytes
Versions: 4
Compression:
Stored size: 585 Bytes
Contents
module OmgValidator module Validators # Checks whether input only contains alpha-numberic characters # # validates :title, alpha_numberic: true class AlphaNumericValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) return nil if value.nil? reg = /^([a-z0-9])+$/i unless reg.match(value) record.errors[attribute] = "must contain only alpha-numeric characters" end end end end end ActiveModel::Validations::AlphaNumericValidator = OmgValidator::Validators::AlphaNumericValidator
Version data entries
4 entries across 4 versions & 1 rubygems