• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP validator函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中validator函数的典型用法代码示例。如果您正苦于以下问题:PHP validator函数的具体用法?PHP validator怎么用?PHP validator使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了validator函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: register

 public function register()
 {
     if (is_post()) {
         $this->loadHelper('Validator');
         if (captcha()) {
             $data = ['email' => validate('email', 'email'), 'username' => validate('required', 'username'), 'password' => password_hash(validate('required', 'register_token'), PASSWORD_BCRYPT), 'token' => str_rand(40)];
             if (validator($data)) {
                 if ($this->user->checkExistUser($data['email'])) {
                     $data2 = ['firstname' => validate('required', 'firstname'), 'lastname' => validate('required', 'lastname'), 'nickname' => validate('required', 'nickname'), 'major' => validate('required', 'major')];
                     if (validator($data2)) {
                         $this->user->createUser($data, $data2);
                         $validate = $this->user->validate($data['email'], $_POST['register_token']);
                         if (!empty($validate)) {
                             $_SESSION['auth'] = $validate;
                             $_SESSION['user'] = $this->user->getDetail($validate['id']);
                             cache_forgot('user.members.' . user('major'));
                             cache_forgot('user.get.members.' . user('major'));
                         }
                     }
                 }
             }
         }
     }
     return redirect('');
 }
开发者ID:Jakkarin,项目名称:Anchor-system-for-branch-or-group,代码行数:25,代码来源:AuthController.php


示例2: validate_lead

 protected function validate_lead($data)
 {
     $messages = array('meta.company.required' => 'Company name is required', 'meta.phone.required' => 'Phone number is required', 'meta.mobile.required' => 'Mobile number is required', 'fullname.required' => 'Fullname is required');
     $rules = ['fullname' => 'required', 'meta.company' => 'required', 'meta.phone' => 'required', 'meta.mobile' => 'required'];
     $validator = validator()->make($data, $rules, $messages);
     return $validator;
 }
开发者ID:xhoiyenx,项目名称:referral,代码行数:7,代码来源:User.php


示例3: validate_update

 protected function validate_update($input, $id)
 {
     $rules = ['fullname' => 'required', 'usermail' => 'required|email|unique:members,usermail,' . $id, 'mobile' => 'required|numeric', 'address' => 'required'];
     $messages = array('fullname.required' => 'Fullname is required', 'usermail.required' => 'Email is required', 'usermail.confirmed' => 'Email confirmation does not match.', 'usermail.unique' => 'Email has already been taken.', 'mobile.required' => 'Mobile number is required', 'mobile.numeric' => 'Mobile number needs all numeric', 'address.required' => 'Address is required');
     $validator = validator()->make($input, $rules, $messages);
     return $validator;
 }
开发者ID:xhoiyenx,项目名称:referral,代码行数:7,代码来源:Member.php


示例4: validate

 /**
  * @throws Exception
  */
 protected function validate()
 {
     $validator = validator($this->data, $this->rules);
     if ($validator->fails()) {
         throw new Exception('Invalid data: ' . $validator->getMessageBag()->first());
     }
 }
开发者ID:timmcleod,项目名称:laravel-view-model,代码行数:10,代码来源:BaseViewModel.php


示例5: validate

 protected function validate($data)
 {
     $messages = array('name.required' => 'Name is required', 'price.required' => 'Price is required', 'fee.required' => 'Referral fee is required');
     $rules = ['name' => 'required', 'price' => 'required', 'fee' => 'required'];
     $validator = validator()->make($data, $rules, $messages);
     return $validator;
 }
开发者ID:xhoiyenx,项目名称:referral,代码行数:7,代码来源:Solution.php


示例6: __construct

 public function __construct(GroupRepo $groupRepo)
 {
     parent::__construct();
     validator()->extend('max_depth', function ($name, $groupId) use($groupRepo) {
         //			$groupRepo->getCurrentDepth($groupId);
         //			dd( __LINE__ . ':[' . __FILE__ . ']', $item1, $item2, $item3 );
     });
 }
开发者ID:donny5300,项目名称:translations,代码行数:8,代码来源:StoreGroupRequest.php


示例7: validator

 private function validator($data, $type)
 {
     $rules = config("mailrules.{$type}", 'mailrules.basic');
     $messages = config("mailmessages.{$type}", 'mailmessages.basic');
     if (is_array($data)) {
         return validator($data, $rules, $messages);
     }
     return false;
 }
开发者ID:wdmtech,项目名称:laravel-mail,代码行数:9,代码来源:Mail.php


示例8: validate

 protected function validate($data, $id = null)
 {
     $messages = array('fullname.required' => 'Name is required', 'usermail.required' => 'Email is required', 'usermail.unique' => 'Email has already been taken', 'mobile.required' => 'Mobile number is required', 'mobile.numeric' => 'Mobile number needs all numeric');
     $rules = ['fullname' => 'required', 'usermail' => 'required|email|unique:sales,usermail,' . $id, 'mobile' => 'required|numeric', 'password' => 'required|confirmed'];
     if (!is_null($id)) {
         $rules['password'] = 'sometimes|confirmed';
     }
     $validator = validator()->make($data, $rules, $messages);
     return $validator;
 }
开发者ID:xhoiyenx,项目名称:referral,代码行数:10,代码来源:Sales.php


示例9: validate

 protected function validate($data, $id = null)
 {
     $messages = array('company.required' => 'Company name is required', 'phone.required' => 'Contact number is required', 'phone.numeric' => 'Contact number needs all numeric', 'fullname.required' => 'Fullname is required', 'tnc.accepted' => 'Please check terms and conditions', 'introduce.required' => 'Please fill info on how will you introduce us', 'solutions.required' => 'Please select one or more solutions available', 'company.leadcheck' => 'You just add another lead with the same company name in last 24 hours');
     $rules = ['fullname' => 'required', 'company' => 'required|leadcheck', 'phone' => 'required|numeric', 'usermail' => 'sometimes|email', 'tnc' => 'accepted', 'introduce' => 'required', 'solutions' => 'required'];
     if (!is_null($id)) {
         unset($rules['tnc']);
     }
     $validator = validator()->make($data, $rules, $messages);
     return $validator;
 }
开发者ID:xhoiyenx,项目名称:referral,代码行数:10,代码来源:Lead.php


示例10: index

 public function index()
 {
     $str = request('str');
     $validator = validator(['str' => $str], ['str' => 'required']);
     if ($validator->fails()) {
         $messages = $validator->messages();
         return $messages->first('str');
     }
     //TODO 支持大写输出
     return md5($str);
 }
开发者ID:LuckyHJH,项目名称:tools,代码行数:11,代码来源:Md5Controller.php


示例11: index

 function index()
 {
     //生成二维码图片(直接调用第三方接口 http://www.liantu.com/pingtai/)
     $str = request('str');
     $validator = validator(['str' => $str], ['str' => 'required']);
     if ($validator->fails()) {
         $messages = $validator->messages();
         return $messages->first('str');
     }
     $content = file_get_contents('http://qr.liantu.com/api.php?text=' . $str);
     return response($content)->header('Content-Type', 'image/png');
 }
开发者ID:LuckyHJH,项目名称:tools,代码行数:12,代码来源:QrController.php


示例12: isValid

 public function isValid($userData, $user)
 {
     if ($user->password != null && $userData['password'] == null) {
         unset($this->rules['password']);
         unset($this->rules['password_confirmation']);
     }
     if ($user->email != null && $userData['email'] == $user->email) {
         $this->rules['email'] = 'required|email|min:6';
     }
     $validate = validator($userData, $this->rules);
     return $validate;
 }
开发者ID:haster312,项目名称:laravel_rikkei,代码行数:12,代码来源:User.php


示例13: newItemWith

 public static function newItemWith(array $attributes)
 {
     $validator = validator($attributes, ["article_id" => "required", "article_type" => "required", "name" => "required", "price" => "required|int", "quantity" => "int", "attributes" => "array"]);
     if ($validator->fails()) {
         throw new InvalidCartItemException();
     }
     $item = new static($attributes);
     if (isset($attributes["attributes"])) {
         foreach ($attributes["attributes"] as $attribute => $value) {
             $item->setCustomAttribute($attribute, $value, false);
         }
     }
     return $item;
 }
开发者ID:dvlpp,项目名称:merx,代码行数:14,代码来源:CartItem.php


示例14: __construct

 public function __construct()
 {
     parent::__construct();
     validator()->extend('unique_array', function ($attributes, $values) {
         $array = [];
         foreach ($values as $key => $value) {
             if (in_array($value, $array)) {
                 return false;
             }
             $array[] = $value;
         }
         return true;
     });
 }
开发者ID:donny5300,项目名称:translations,代码行数:14,代码来源:Request.php


示例15: index

 function index()
 {
     $str = request('str');
     $type = request('type');
     $validator = validator(['str' => $str], ['str' => 'required']);
     if ($validator->fails()) {
         $messages = $validator->messages();
         return $messages->first('str');
     }
     if ($type == 'decode') {
         return base64_decode($str);
     } else {
         return base64_encode($str);
     }
 }
开发者ID:LuckyHJH,项目名称:tools,代码行数:15,代码来源:Base64Controller.php


示例16: delete

 /**
  * Delete().
  *
  * This will delete the trip out off the application.
  *
  * @param Request $request
  * @param int $id , The trip id. id = increment id -> Database
  * @return response
  */
 public function delete(Request $request, $id)
 {
     $validator = validator()->make($request->all(), ['id' => 'required']);
     /** @var mixed $validator */
     if ($validator->fails()) {
         $dataArray = ['status' => ['code' => 50, 'message' => 'id required']];
         return response()->json($dataArray)->header('Content-Type', 'application/json', $dataArray['status']['code']);
     }
     $trip = User::find($id);
     if (auth()->gaurd('api')->user()->id != $trip->user_id) {
         $dataArray = ['status' => ['code' => 400, 'message' => 'You cannot delete the trips because it is not yours.']];
     }
     $dataArray = [];
     return response()->json($dataArray)->header('Content-Type', 'application/json', $dataArray['status']['code']);
 }
开发者ID:Tjoosten,项目名称:refugee,代码行数:24,代码来源:apitripsController.php


示例17: validate

 /**
  * Validates current attributes against rules
  */
 public function validate()
 {
     $validator = \validator($this->attributes, $this->overrideNormalRules(static::$rules), static::$messages);
     $validator->addExtensions($this->overrideCustomRules(static::$customRules));
     foreach ($this->overrideComplexRules(static::$complexRules) as $field => $validation) {
         $rules = $validation["rules"];
         $check = $validation["check"];
         $validator->sometimes($field, $rules, $check);
     }
     if ($validator->passes()) {
         return true;
     }
     $this->setErrors($validator->messages());
     return false;
 }
开发者ID:williamcarril,项目名称:model-validation,代码行数:18,代码来源:Model.php


示例18: boot

 public function boot()
 {
     Collection::macro('associate', function ($key = null, $value = null) {
         return $this->reduce(function ($items, $values) use($key, $value) {
             $values = collect($values);
             list($key, $value) = is_null($key) ? $values->take(2)->values()->toArray() : [$values->get($key), $values->get($value)];
             return $items->put($key, $value);
         }, new static());
     });
     Collection::macro('fail', function ($rules = []) {
         return $this->filter(function ($item) use($rules) {
             return validator()->make($item, $rules)->fails();
         });
     });
     Collection::macro('ifAny', function ($callback) {
         if (!$this->isEmpty()) {
             return $callback($this);
         }
         return $this;
     });
     Collection::macro('ifEmpty', function ($callback) {
         if ($this->isEmpty()) {
             return $callback($this);
         }
         return $this;
     });
     Collection::macro('pass', function ($rules = []) {
         return $this->filter(function ($item) use($rules) {
             return validator()->make($item, $rules)->passes();
         });
     });
     Collection::macro('then', function ($callback) {
         return $callback($this);
     });
     Collection::macro('transpose', function () {
         $items = array_map(function (...$items) {
             return $items;
         }, ...$this->values());
         return new static($items);
     });
     Collection::macro('validate', function ($rules = []) {
         return $this->each(function ($item) use($rules) {
             if (validator()->make($item, $rules)->fails()) {
                 throw new ValidationException($this);
             }
         });
     });
 }
开发者ID:laugharn,项目名称:macros,代码行数:48,代码来源:CollectionServiceProvider.php


示例19: post

 public function post()
 {
     $validator = validator();
     $request = request();
     $post = $request->post();
     $username = $validator->required()->validate('Username', $post['username'] ?? '', 'trim');
     $password = $validator->required()->validate('Password', $post['password'] ?? '', 'trim');
     $check = $validator->match($password, 'Password')->setError('Passwords must match')->validate('Password', $post['check'] ?? '', 'trim');
     $data = array('username' => $username, 'password' => $password, 'check' => $check);
     if ($validator->hasErrors()) {
         System::alerts()->fromValidator($validator);
         return $this->getPage($data);
     }
     session()->set('account', $data);
     session()->set('account-ok', true);
     redirect(getURL('/install/finish'));
 }
开发者ID:opis-colibri,项目名称:install,代码行数:17,代码来源:Account.php


示例20: post

 /**
  * @return array
  */
 public function post()
 {
     $validator = validator();
     $post = request()->post();
     $username = $validator->required()->validate('Username', $post['username'] ?? '', 'trim');
     $password = $validator->required()->validate('Password', $post['password'] ?? '', 'trim');
     $check = $validator->match($password, 'Password')->setError('Passwords must match')->validate('Check', $post['check'] ?? '', 'trim');
     if (!$validator->hasErrors()) {
         config()->write('manager', array('username' => $username, 'password' => md5($password)));
         System::alerts()->success(t('You have successfully created your administrator account'));
         cache()->clear();
         redirect(getURL('/module-manager/login'));
     }
     System::alerts()->fromValidator($validator);
     $values = ['username' => $username, 'password' => $password, 'check' => $check];
     return $this->getPage($values);
 }
开发者ID:opis-colibri,项目名称:manager,代码行数:20,代码来源:Create.php



注:本文中的validator函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP validemail函数代码示例发布时间:2022-05-23
下一篇:
PHP validation_errors函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap