Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added tests

  • Loading branch information...
commit 2d7f6fc707189fbef4d56508664d81236cfa6558 1 parent 50e3307
spiliot authored
View
17 lib/Cake/Test/Case/Utility/ValidationTest.php
@@ -1958,29 +1958,38 @@ public function testExtension() {
* @return void
*/
public function testMoney() {
+ $this->assertTrue(Validation::money('100'));
+ $this->assertTrue(Validation::money('100.11'));
+ $this->assertTrue(Validation::money('100.112'));
+ $this->assertTrue(Validation::money('100.1'));
+ $this->assertTrue(Validation::money('100.111,1'));
+ $this->assertTrue(Validation::money('100.111,11'));
+ $this->assertFalse(Validation::money('100.111,111'));
+ $this->assertFalse(Validation::money('text'));
+
$this->assertTrue(Validation::money('$100'));
$this->assertTrue(Validation::money('$100.11'));
$this->assertTrue(Validation::money('$100.112'));
- $this->assertFalse(Validation::money('$100.1'));
+ $this->assertTrue(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->assertTrue(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->assertTrue(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->assertTrue(Validation::money('100.1€', 'right'));
$this->assertFalse(Validation::money('100.1111€', 'right'));
}
View
2  lib/Cake/Utility/Validation.php
@@ -528,7 +528,7 @@ public static function maxLength($check, $max) {
* @return boolean Success
*/
public static function money($check, $symbolPosition = 'left') {
- $money = '(?!0,?\d)(?:\d{1,3}(?:([, .])\d{3})?(?:\1\d{3})*|(?:\d+))((?!\1)[,.]\d{1})?';
+ $money = '(?!0,?\d)(?:\d{1,3}(?:([, .])\d{3})?(?:\1\d{3})*|(?:\d+))((?!\1)[,.]\d{1,2})?';
if ($symbolPosition === 'right') {
$regex = '/^' . $money . '(?<!\x{00a2})\p{Sc}?$/u';
} else {
Please sign in to comment.
Something went wrong with that request. Please try again.