jboursiquot/maildis

View on GitHub
lib/maildis/validation_utils.rb

Summary

Maintainability
A
25 mins
Test Coverage
class ValidationUtils

  class << self

    def valid_hostname?(hostname)
      if !hostname || hostname.length > 255 || hostname.scan('..').any?
        return false
      end

      return true if hostname == 'localhost'

      hostname = hostname[0 ... -1] if hostname.index('.', -1)
      return hostname.split('.').collect { |i| i.size <= 63 && !(i.rindex('-', 0) || i.index('-', -1) || i.scan(/[^a-z\d-]/i).any?)}.all?
    end

    def valid_email?(email)
      !email.match(/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i).nil?
    end

  end

end