public function clientValidateAttribute($object, $attribute) { switch ($attribute) { case 'ip': $this->pattern = SourceBans::PATTERN_IP; break; case 'steam': $this->pattern = SourceBans::PATTERN_STEAM; break; } return parent::clientValidateAttribute($object, $attribute); }
/** * Returns the JavaScript needed for performing client-side validation. * @param CModel $object the data object being validated * @param string $attribute the name of the attribute to be validated. * @return string the client-side validation script. * @see CActiveForm::enableClientValidation * @since 1.1.7 */ public function clientValidateAttribute($object, $attribute) { if (!$this->_version === 'both') { if (is_null($this->message)) { Yii::t(__CLASS__, '{attribute} is not a valid IP adress.'); } $this->detectPattern(); return parent::clientValidateAttribute($object, $attribute); } else { // no client side validation return ''; } }
public function clientValidateAttribute($object, $attribute) { switch ($object->auth) { case SBAdmin::AUTH_STEAM: $this->pattern = SourceBans::PATTERN_STEAM; break; case SBAdmin::AUTH_IP: $this->pattern = SourceBans::PATTERN_IP; break; default: return; } return parent::clientValidateAttribute($object, $attribute); }
/** * {@inheritDoc} * @see CRegularExpressionValidator::clientValidateAttribute() */ public function clientValidateAttribute($object, $attribute) { $this->not = false; $js = parent::clientValidateAttribute($object, $attribute); $message = $this->getMessage(); $errormsg = Yii::t('validator', 'The "pattern" property must be specified with an unique capture group.'); $pattern = $this->pattern; $pattern = preg_replace('/\\\\x\\{?([0-9a-fA-F]+)\\}?/', '\\u$1', $pattern); $delim = substr($pattern, 0, 1); $endpos = strrpos($pattern, $delim, 1); $flag = substr($pattern, $endpos + 1); if ($delim !== '/') { $pattern = '/' . str_replace('/', '\\/', substr($pattern, 1, $endpos - 1)) . '/'; } else { $pattern = substr($pattern, 0, $endpos + 1); } if (!empty($flag)) { $pattern .= preg_replace('/[^igm]/', '', $flag); } $morejs = "\nfunction getMatches(string, regex, index) {\n\tvar matches = [];\n\tvar match;\n\twhile (match = regex.exec(string)) {\n\t\tmatches.push(match[index]);\n\t}\n\treturn matches;\n}\n\nif(" . ($this->allowEmpty ? "jQuery.trim(value)!='' && " : '') . "true) {\n\tvar matches = getMatches(value, {$pattern}, 1);\n\tif(matches.length == 1) {\n\t\tvar match = matches[0];\n\t\tvar sum = 0;\n\t\tvar even = false;\n\t\tfor(var digit = match.length - 1; digit >= 0; digit--) {\n\t\t\tvar num = parseInt(match.charAt(digit), 10);\n\t\t\tif(even) {\n\t\t\t\tnum *= 2;\n\t\t\t\tnum = (num % 10) + Math.floor(num / 10);\n\t\t\t}\n\t\t\teven = !even;\n\t\t\tsum += num;\n\t\t}\n\t\tif(sum % 10 != 0) {\n\t\t\tmessages.push(" . CJSON::encode($message) . ");\n\t\t}\n\t} else {\n\t\tmessages.push(" . CJSON::encode($errormsg) . ");\n\t}\n}\n"; return $js . $morejs; }
/** * {@inheritDoc} * @see CRegularExpressionValidator::clientValidateAttribute() */ public function clientValidateAttribute($object, $attribute) { if (empty($this->message)) { $this->message = Yii::t('yiiext.validator', '{attribute} is not a valid IP adress.'); } $this->makeupPattern(); return parent::clientValidateAttribute($object, $attribute); }