Skip to content
Browse files

Merge branch 'uuid' of https://github.com/klappy/ruby_regex

  • Loading branch information...
2 parents e0779c5 + 8f24626 commit e1603bff12ead415f03514354b0f75e5965ac5f7 @eparreno committed Sep 27, 2011
Showing with 12 additions and 0 deletions.
  1. +4 −0 lib/ruby_regex.rb
  2. +8 −0 test/ruby_regex_test.rb
View
4 lib/ruby_regex.rb
@@ -49,4 +49,8 @@ module RubyRegex
# From the email regex research: http://fightingforalostcause.net/misc/2006/compare-email-regex.php
# 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
+
+ # 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
View
8 test/ruby_regex_test.rb
@@ -123,6 +123,14 @@ def test_invalid_delicious_usernames
check_invalid_regex RubyRegex::DeliciousUsername, ['nickel 84', 'h.ppywebcoder']
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
def load_fixture( name )
YAML.load( File.read( File.join( File.dirname(__FILE__), 'fixtures', "#{name}.yml" ) ) )

0 comments on commit e1603bf

Please sign in to comment.
Something went wrong with that request. Please try again.