Skip to content

Commit

Permalink
Merge branch 'uuid' of https://github.com/klappy/ruby_regex
Browse files Browse the repository at this point in the history
  • Loading branch information
eparreno committed Sep 27, 2011
2 parents e0779c5 + 8f24626 commit e1603bf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/ruby_regex.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -49,4 +49,8 @@ module RubyRegex
# From the email regex research: http://fightingforalostcause.net/misc/2006/compare-email-regex.php # From the email regex research: http://fightingforalostcause.net/misc/2006/compare-email-regex.php
# Authors: James Watts and Francisco Jose Martin Moreno # Authors: James Watts and Francisco Jose Martin Moreno
Email = /^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w-]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i Email = /^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w-]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i

# UUID
# Validates a UUID as defined: http://en.wikipedia.org/wiki/Universally_unique_identifier
UUID = /^(\h{32}|\h{8}-\h{4}-\h{4}-\h{4}-\h{12})$/
end end
8 changes: 8 additions & 0 deletions test/ruby_regex_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ def test_invalid_delicious_usernames
check_invalid_regex RubyRegex::DeliciousUsername, ['nickel 84', 'h.ppywebcoder'] check_invalid_regex RubyRegex::DeliciousUsername, ['nickel 84', 'h.ppywebcoder']
end end


def test_valid_uuids
check_valid_regex RubyRegex::UUID, ['550e8400e29b41d4a716446655440000', '550e8400-e29b-41d4-a716-446655440000', '6ba7b8109dad11d180b400c04fd430c8', '6ba7b810-9dad-11d1-80b4-00c04fd430c8']
end

def test_invalid_uuids
check_invalid_regex RubyRegex::UUID, ['6ba7b810-9dad-11d180b400c04fd430c8', 'zba7b810-9dad-11d1-80b4-00c04fd430c8', '6ba7b81-9ad-1d1-0b4-00c04fd430c8', '1234', 'asdf', '555-555-5555', 'abcd@qwerty.com']
end

private private
def load_fixture( name ) def load_fixture( name )
YAML.load( File.read( File.join( File.dirname(__FILE__), 'fixtures', "#{name}.yml" ) ) ) YAML.load( File.read( File.join( File.dirname(__FILE__), 'fixtures', "#{name}.yml" ) ) )
Expand Down

0 comments on commit e1603bf

Please sign in to comment.