diff --git a/cake/libs/validation.php b/cake/libs/validation.php index 13f1e2c8a..eb2a3f83e 100644 --- a/cake/libs/validation.php +++ b/cake/libs/validation.php @@ -577,10 +577,10 @@ class Validation extends Object { $_this->check = $check; switch ($symbolPosition) { case 'left': - $_this->regex = '/^(?!\\u00a2)\\p{Sc}?(?!0,?\\d)(?:\\d{1,3}(?:([, .])\\d{3})?(?:\\1\\d{3})*|(?:\\d+))((?!\\1)[,.]\\d{2})?$/'; + $_this->regex = '/^(?!\x{00a2})\p{Sc}?(?!0,?\d)(?:\d{1,3}(?:([, .])\d{3})?(?:\1\d{3})*|(?:\d+))((?!\1)[,.]\d{2})?$/u'; break; case 'right': - $_this->regex = '/^(?!0,?\\d)(?:\\d{1,3}(?:([, .])\\d{3})?(?:\\1\\d{3})*|(?:\\d+))((?!\\1)[,.]\\d{2})?(?regex = '/^(?!0,?\d)(?:\d{1,3}(?:([, .])\d{3})?(?:\1\d{3})*|(?:\d+))((?!\1)[,.]\d{2})?(?_check(); diff --git a/cake/tests/cases/libs/validation.test.php b/cake/tests/cases/libs/validation.test.php index 0cba3af5d..738fb73a7 100644 --- a/cake/tests/cases/libs/validation.test.php +++ b/cake/tests/cases/libs/validation.test.php @@ -1282,6 +1282,33 @@ class ValidationTestCase extends UnitTestCase { $this->assertFalse(Validation::extension(array('noextension', 'extension.JPG', 'extension.gif', 'extension.png'))); $this->assertFalse(Validation::extension(array('extension.pdf', 'extension.JPG', 'extension.gif', 'extension.png'))); } + + function testMoney() { + $this->assertTrue(Validation::money('$100')); + $this->assertTrue(Validation::money('$100.11')); + $this->assertTrue(Validation::money('$100.112')); + $this->assertFalse(Validation::money('$100.1')); + $this->assertFalse(Validation::money('$100.1111')); + $this->assertFalse(Validation::money('text')); + + $this->assertTrue(Validation::money('100', 'right')); + $this->assertTrue(Validation::money('100.11$', 'right')); + $this->assertTrue(Validation::money('100.112$', 'right')); + $this->assertFalse(Validation::money('100.1$', 'right')); + $this->assertFalse(Validation::money('100.1111$', 'right')); + + $this->assertTrue(Validation::money('€100')); + $this->assertTrue(Validation::money('€100.11')); + $this->assertTrue(Validation::money('€100.112')); + $this->assertFalse(Validation::money('€100.1')); + $this->assertFalse(Validation::money('€100.1111')); + + $this->assertTrue(Validation::money('100', 'right')); + $this->assertTrue(Validation::money('100.11€', 'right')); + $this->assertTrue(Validation::money('100.112€', 'right')); + $this->assertFalse(Validation::money('100.1€', 'right')); + $this->assertFalse(Validation::money('100.1111€', 'right')); + } /* function TestFile() { $this->assertTrue(Validation::file(WWW_ROOT . 'img' . DS . 'cake.icon.gif'));