Consoloidate duplicate regex strings in money() validation.

This commit is contained in:
predominant 2010-04-23 17:04:25 +10:00
parent 396c025529
commit f65e481ebf

View file

@ -472,10 +472,11 @@ class Validation {
* @return boolean Success * @return boolean Success
*/ */
public static function money($check, $symbolPosition = 'left') { public static function money($check, $symbolPosition = 'left') {
$money = '(?!0,?\d)(?:\d{1,3}(?:([, .])\d{3})?(?:\1\d{3})*|(?:\d+))((?!\1)[,.]\d{2})?';
if ($symbolPosition == 'right') { if ($symbolPosition == 'right') {
$regex = '/^(?!0,?\d)(?:\d{1,3}(?:([, .])\d{3})?(?:\1\d{3})*|(?:\d+))((?!\1)[,.]\d{2})?(?<!\x{00a2})\p{Sc}?$/u'; $regex = '/^' . $money . '(?<!\x{00a2})\p{Sc}?$/u';
} else { } else {
$regex = '/^(?!\x{00a2})\p{Sc}?(?!0,?\d)(?:\d{1,3}(?:([, .])\d{3})?(?:\1\d{3})*|(?:\d+))((?!\1)[,.]\d{2})?$/u'; $regex = '/^(?!\x{00a2})\p{Sc}?' . $money . '$/u';
} }
return self::_check($check, $regex); return self::_check($check, $regex);
} }