Module: Mbrao::Validations::ClassMethods
- Defined in:
- lib/mbrao/parser.rb
Overview
Class methods.
Instance Method Summary (collapse)
-
- (Boolean) is_email?(text)
Checks if the text is a valid email.
-
- (Boolean) is_url?(text)
Checks if the text is a valid URL.
Instance Method Details
- (Boolean) is_email?(text)
Checks if the text is a valid email.
136 137 138 139 |
# File 'lib/mbrao/parser.rb', line 136 def is_email?(text) regex = /^([a-z0-9_\.\-\+]+)@([\da-z\.\-]+)\.([a-z\.]{2,6})$/i text.ensure_string.strip =~ regex end |
- (Boolean) is_url?(text)
Checks if the text is a valid URL.
145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/mbrao/parser.rb', line 145 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 |