Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added Validation::uuid(). Updated test cases.

Signed-off-by: Mark Story <mark@mark-story.com>
  • Loading branch information...
commit 5ae0164574c9bf46d63574532153b1fe4aae4f68 1 parent cf69753
@tPl0ch tPl0ch authored markstory committed
View
14 cake/libs/validation.php
@@ -798,6 +798,20 @@ function ssn($check, $regex = null, $country = null) {
}
/**
+ * Checks that a value is a valid uuid - http://tools.ietf.org/html/rfc4122
+ *
+ * @param string $check Value to check
+ * @return boolean Success
+ * @access public
+ */
+ function uuid($check) {
+ $_this =& Validation::getInstance();
+ $_this->check = $check;
+ $_this->regex = '/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i';
+ return $_this->_check();
+ }
+
+/**
* Checks that a value is a valid URL according to http://www.w3.org/Addressing/URL/url-spec.txt
*
* The regex checks for the following component parts:
View
11 cake/tests/cases/libs/validation.test.php
@@ -1849,6 +1849,17 @@ function testUrl() {
$this->assertTrue(Validation::url('http://example.com/~userdir/'));
}
+ function testUuid() {
+ $this->assertTrue(Validation::uuid('550e8400-e29b-11d4-a716-446655440000'));
+ $this->assertFalse(Validation::uuid('BRAP-e29b-11d4-a716-446655440000'));
+ $this->assertTrue(Validation::uuid('550E8400-e29b-11D4-A716-446655440000'));
+ $this->assertFalse(Validation::uuid('550e8400-e29b11d4-a716-446655440000'));
+ $this->assertFalse(Validation::uuid('550e8400-e29b-11d4-a716-4466440000'));
+ $this->assertFalse(Validation::uuid('550e8400-e29b-11d4-a71-446655440000'));
+ $this->assertFalse(Validation::uuid('550e8400-e29b-11d-a716-446655440000'));
+ $this->assertFalse(Validation::uuid('550e8400-e29-11d4-a716-446655440000'));
+ }
+
/**
* testInList method
*
Please sign in to comment.
Something went wrong with that request. Please try again.