Sha256: f77378e2bb43274c4d6751959ce45937149ed09e670ea70bc5a3a6e4422ec6b1
Contents?: true
Size: 1.53 KB
Versions: 1
Compression:
Stored size: 1.53 KB
Contents
module MoreCoreExtensions module StringFormats # From: http://www.regular-expressions.info/email.html RE_EMAIL = %r{\A[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\z} def email? !!(self =~ RE_EMAIL) end # From: Regular Expression Cookbook: 7.15 Validating Domain Names RE_DOMAINNAME = %r{^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$}i def domain_name? !!(self =~ RE_DOMAINNAME) end # From: Regular Expression Cookbook: 7.16 Matching IPv4 Addresses RE_IPV4 = %r{^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$} def ipv4? !!(self =~ RE_IPV4) end # From: Regular Expression Cookbook: 7.17 Matching IPv6 Addresses RE_IPV6 = %r{^(?:(?:(?:[A-F0-9]{1,4}:){6}|(?=(?:[A-F0-9]{0,4}:){0,6}(?:[0-9]{1,3}\.){3}[0-9]{1,3}$)(([0-9A-F]{1,4}:){0,5}|:)((:[0-9A-F]{1,4}){1,5}:|:))(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|(?:[A-F0-9]{1,4}:){7}[A-F0-9]{1,4}|(?=(?:[A-F0-9]{0,4}:){0,7}[A-F0-9]{0,4}$)(([0-9A-F]{1,4}:){1,7}|:)((:[0-9A-F]{1,4}){1,7}|:))$}i def ipv6? !!(self =~ RE_IPV6) end def ipaddress? ipv4? || ipv6? end RE_INTEGER = %r{^-?[0-9]+$} def integer? !!(self =~ RE_INTEGER) end RE_GUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/ def guid? !!(self =~ RE_GUID) end end end String.send(:include, MoreCoreExtensions::StringFormats)
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
more_core_extensions-3.1.1 | lib/more_core_extensions/core_ext/string/formats.rb |