首页 > 其他分享 >yii2 rules验证规则大全

yii2 rules验证规则大全

时间:2024-03-30 14:25:35浏览次数:21  
标签:name 验证 rules ip message yii2 email 大全

yii2 rules验证规则大全

required : 必须值验证属性

[['name','email'],'required']
[['name'],'required','message'=>'提示信息']

email : 邮箱验证

[['email'], 'email','message'=>'邮箱格式错误'],

match : 正则验证

[
'phone',
'match',
'pattern' => '/^13[0-9]{9}$|14[0-9]{9}$|15[0-9]{9}$|17[0-9]{9}$|18[0-9]{9}$/',
'message' => '手机号格式不正确'
]

url : 网址

['url', 'url', 'defaultScheme' => 'https']

captcha : 验证码

['verificationCode', 'captcha']

compare : 比较

['email', 'compare', 'compareValue' => 30, 'operator' => '>=']

filter : 滤镜

[['name', 'email'], 'filter', 'filter' => 'trim', 'skipOnArray' => true]

in : 范围

['level', 'in', 'range' => [1, 2, 3]];

unique : 唯一性

['username', 'unique']

integer : 整数

['age', 'integer']

number : 数字

['salary', 'number']

date : 日期

[['start'], 'date', 'format'=>'yyyy/MM/dd HH:mm:ss']

string : 字符串

['username', 'string', 'length' => [4, 24]];

ip:验证IP

['ip', 'ip']

标签:name,验证,rules,ip,message,yii2,email,大全
From: https://www.cnblogs.com/hu308830232/p/18105414

相关文章

  • Yii2行为用法
    Yii2行为用法使用行为(behavior)可以在不修改现有类的情况下,对类的功能进行扩充行为类(app\common\behaviors\MyBehavior)<?phpnamespaceapp\common\behaviors;useyii\base\Behavior;classMyBehaviorextendsBehavior{public$name;public$age;......
  • yii2模块
    yii2模块模块是独立的软件单元,由模型, 视图, 控制器和其他支持组件组成, 终端用户可以访问在应用主体中已安装的模块的控制器, 模块被当成小应用主体来看待,和应用主体不同的是, 模块不能单独部署,必须属于某个应用主体。模块文件结构modulesadmincontrollers......
  • yii2服务定位器
    yii2服务定位器服务定位器是注册和访问组件的对象注册组件useyii\di\ServiceLocator;useyii\caching\FileCache;$locator=newServiceLocator;//通过一个可用于创建该组件的类名,注册"cache"(缓存)组件。$locator->set('cache','yii\caching\ApcCache');//通过......
  • yii2响应(Responses)
    yii2响应(Responses)状态码Yii::$app->response->statusCode=200;异常yii\web\BadRequestHttpException:statuscode400.yii\web\ConflictHttpException:statuscode409.yii\web\ForbiddenHttpException:statuscode403.yii\web\GoneHttpException:......
  • yii2过滤器
    yii2过滤器过滤器是控制器动作执行之前或之后执行的对象。示例过滤器common\components\ActionTimeFilter<?phpnamespaceapp\common\components;useYii;useyii\base\ActionFilter;classActionTimeFilterextendsActionFilter{private$_startTime;......
  • yii2 资源
    yii2资源AppAsset.php<?phpnamespaceapp\assets;useyii\web\AssetBundle;classAppAssetextendsAssetBundle{public$basePath='@webroot';public$baseUrl='@web';public$css=['css/site.css�......
  • yii2请求组件
    yii2请求组件应用的请求是用yii\web\Request对象来表示的请求参数$request=Yii::$app->request;$get=$request->get();//等价于:$get=$_GET;$id=$request->get('id');//等价于:$id=isset($_GET['id'])?$_GET['id']:null;$i......
  • yii2视图
    yii2视图示例代码<?phpuseyii\helpers\Html;useyii\widgets\ActiveForm;/*@var$thisyii\web\View*//*@var$formyii\widgets\ActiveForm*//*@var$modelapp\models\LoginForm*/$this->title='Login';?><h1><?=Ht......
  • yii2 模型
    yii2模型Yii2的模型(Model)是MVC(Model-View-Controller)设计模式中的一部分,它代表业务数据、规则和逻辑的对象。模型通常用于处理与数据相关的业务逻辑,如数据的验证、访问和修改等。模型示例代码<?phpnamespaceapp\models;useYii;useyii\db\ActiveRecord;......
  • yii2 配置bootstrap使用
    yii2配置bootstrap使用配置config/web.php添加people<?php...$config=[...'bootstrap'=>['log','people'],...'components'=>['people'=>['class'......