Class: ValidationUtils
- Inherits:
-
Object
- Object
- ValidationUtils
- Defined in:
- lib/maildis/validation_utils.rb
Class Method Summary collapse
Class Method Details
.valid_email?(email) ⇒ Boolean
16 17 18 |
# File 'lib/maildis/validation_utils.rb', line 16 def valid_email?(email) !email.match(/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i).nil? end |
.valid_hostname?(hostname) ⇒ Boolean
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/maildis/validation_utils.rb', line 5 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 |