Module: Mbrao::Validations::ClassMethods
- Defined in:
- lib/mbrao/parser.rb
Overview
Class methods.
Instance Method Summary collapse
-
#is_email?(text) ⇒ Boolean
Checks if the text is a valid email.
-
#is_url?(text) ⇒ Boolean
Checks if the text is a valid URL.
Instance Method Details
#is_email?(text) ⇒ Boolean
Checks if the text is a valid email.
113 114 115 116 |
# File 'lib/mbrao/parser.rb', line 113 def is_email?(text) regex = /^([a-z0-9_\.\-\+]+)@([\da-z\.\-]+)\.([a-z\.]{2,6})$/i text.ensure_string.strip =~ regex end |
#is_url?(text) ⇒ Boolean
Checks if the text is a valid URL.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/mbrao/parser.rb', line 122 def is_url?(text) regex = / ^( ([a-z0-9\-]+:\/\/) #PROTOCOL (([\w-]+\.)?) # LOWEST TLD ([\w-]+) # 2nd LEVEL TLD (\.[a-z]+) # TOP TLD ((:\d+)?) # PORT ([\S|\?]*) # PATH, QUERYSTRING AND FRAGMENT )$ /ix text.ensure_string.strip =~ regex end |