本文整理汇总了PHP中validator函数的典型用法代码示例。如果您正苦于以下问题:PHP validator函数的具体用法?PHP validator怎么用?PHP validator使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了validator函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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('');
}
示例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;
}
示例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;
}
示例4: validate
/**
* @throws Exception
*/
protected function validate()
{
$validator = validator($this->data, $this->rules);
if ($validator->fails()) {
throw new Exception('Invalid data: ' . $validator->getMessageBag()->first());
}
}
示例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;
}
示例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 );
});
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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');
}
示例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;
}
示例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;
}
示例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;
});
}
示例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);
}
}