Sha256: cd4054a8990843b414f9077b0cd82ac915c342bb0686dcb520713172f5d77ddf
Contents?: true
Size: 753 Bytes
Versions: 12
Compression:
Stored size: 753 Bytes
Contents
module ActiveModel module Validations class TwitterValidator < EachValidator def validate_each(record, attribute, value) format = options[:format].to_sym if options[:format] if value.nil? record.errors.add_on_blank(attribute) elsif format == :url match = value.match(/^https?:\/\/(www\.)?twitter.com\/([A-Za-z0-9_]{1,15})$/i) record.errors.add(attribute) unless match && !match[2].nil? # www. is first capture elsif format == :username_with_at record.errors.add(attribute) unless value.match(/^@([A-Za-z0-9_]{1,15})$/i) else record.errors.add(attribute) unless value.match(/^([A-Za-z0-9_]{1,15})$/i) end end end end end
Version data entries
12 entries across 12 versions & 1 rubygems