class Cregexp
Public Class Methods
email(options = {})
click to toggle source
# File lib/cregexp.rb, line 6 def self.email(options = {}) /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i end
hex(options = {})
click to toggle source
Hex Value a3c113 passes #4d82h4 failes(contains h)
# File lib/cregexp.rb, line 25 def self.hex(options = {}) /^#?([a-f0-9]{6}|[a-f0-9]{3})$/ end
image()
click to toggle source
Image Checke if file extension is of a valid image type
# File lib/cregexp.rb, line 31 def self.image /.png|.jpg|.jpeg|.gif|.bmp|.tiff|.PNG|.JPG|.JPEG|.GIF|.BMP|.TIFF$/ end
ip(options = {})
click to toggle source
IP Address
# File lib/cregexp.rb, line 18 def self.ip(options = {}) /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/ end
match(string, matcher, options = {})
click to toggle source
Cregexp.match
(“www.google.com”, :url) => true
# File lib/cregexp.rb, line 36 def self.match(string, matcher, options = {}) !(string =~ send(matcher.to_sym)).nil? end
slug(options = {})
click to toggle source
Slug my-title-here passes my_title_here fails
# File lib/cregexp.rb, line 13 def self.slug(options = {}) /^[a-z0-9-]+$/ end
url(options = {})
click to toggle source
# File lib/cregexp.rb, line 2 def self.url(options = {}) /(^$)|(^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$)/ix end