Module: Mbrao::ParserValidations::ClassMethods
- Defined in:
- lib/mbrao/parser_validations.rb
Overview
Class methods.
Instance Method Summary (collapse)
-
- (Boolean) email?(text)
Checks if the text is a valid email.
-
- (Boolean) url?(text)
Checks if the text is a valid URL.
Instance Method Details
- (Boolean) email?(text)
Checks if the text is a valid email.
19 20 21 |
# File 'lib/mbrao/parser_validations.rb', line 19 def email?(text) /^([a-z0-9_\.\-\+]+)@([\da-z\.\-]+)\.([a-z\.]{2,6})$/i.match(text.ensure_string.strip) end |
- (Boolean) url?(text)
Checks if the text is a valid URL.
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/mbrao/parser_validations.rb', line 27 def url?(text) %r{ ^( ([a-z0-9\-]+:\/\/) #PROTOCOL (([\w-]+\.)?) # LOWEST TLD ([\w-]+) # 2nd LEVEL TLD (\.[a-z]+) # TOP TLD ((:\d+)?) # PORT ([\S|\?]*) # PATH, QUERYSTRING AND FRAGMENT )$ }ix.match(text.ensure_string.strip) end |