lib/app42/base/util.rb in app42-0.6.0 vs lib/app42/base/util.rb in app42-0.6.1
- old
+ new
@@ -1,6 +1,7 @@
require "interact"
+require 'uri'
require "ipaddress"
module App42
module Base
module Util
@@ -292,9 +293,22 @@
if str.match(App42::REGEX) || str.length > 30
message "#{name} should not contain any special character or white space and length should be less than 30.", true, 'red'
return false
else
return str
+ end
+ end
+
+ # Check whether +URL+ is valid OR not
+ # +URL+ should start with +http+ and +https+
+ # And should not contain any special character
+ def validate_url url
+ # Using the URI module distributed with Ruby, We can write own URL_REGEX(defined in constant.rb) too.
+ unless url =~ /^#{URI::regexp}$/
+ message "The provided URL (#{url}) is either not valid or contains white space and special character.", true, 'red'
+ return false
+ else
+ return url
end
end
# Check whether +uploadbackup+ path is valid OR not
# predefined extension are allowed only like .sql, .zip, .dump etc
\ No newline at end of file