/** * Get the Register violin */ public static function get() { // create instance $v = new self(); // add custum rules $v->addFieldMessages(['mail' => ['max' => Language::get('mail.max'), 'email' => Language::get('mail.email')], 'name' => ['max' => Language::get('name.max')], 'pass' => ['max' => Language::get('pass.max')], 'pass_confirm' => ['matches' => Language::get('pass_confirm.matches')]]); // add unique validation $v->addRuleMessage('unique', Language::get('unique')); $v->addRule('unique', function ($val, $in, $args) { return (int) User::where('mail', $val)->where('id', '!=', $args[0])->count() === 0; }); // add unique validation $v->addRuleMessage('num', Language::get('num')); $v->addRule('num', function ($val, $in, $args) { if ($val == '') { return true; } return (int) strlen(preg_replace('![^0-9]+!', '', $val)) === $args[0]; }); // add unique validation $v->addRuleMessage('capitals', Language::get('capitals')); $v->addRule('capitals', function ($val, $in, $args) { if ($val == '') { return true; } return (int) strlen(preg_replace('![^A-Z]+!', '', $val)) === $args[0]; }); // return instance return $v; }