Sha256: a984bc10ecead56ac724650d3ab15e1558cfd2de9062b82e06f744c4b2b881c3
Contents?: true
Size: 1015 Bytes
Versions: 1
Compression:
Stored size: 1015 Bytes
Contents
# frozen_string_literal: true module EmailInquire class EmailValidator def initialize(email) @email = email.downcase end attr_reader :email def valid? return false unless email.count("@") == 1 return false if email.length > 255 name, domain = email.split("@", 2) name_valid?(name) && domain_valid?(domain) end private DOMAIN_REGEXP = / \A (?: (?= [a-z0-9-]{1,63} \. ) [a-z0-9]+ (?: - [a-z0-9]+ )* \. ){1,8} [a-z]{2,63} \z /x def domain_valid?(domain) return false if domain == "" return false unless domain =~ DOMAIN_REGEXP true end NAME_REGEXP = / \A [a-z0-9] [a-z0-9._%+-]{0,63} \z /x def name_valid?(name) return false if name == "" return false if name.length > 64 return false unless name =~ NAME_REGEXP true end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
email_inquire-0.5.0 | lib/email_inquire/email_validator.rb |