<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ## 驗證場景 驗證器重支持定義場景,并且驗證不同場景的數據,例如: ~~~ class ArticleValidate extends Validate { constructor() { const rules = { 'id' : 'require|number', 'content' : 'require|length:1,2000', 'title' : 'require|chsDash|length:4,50' } const message = { 'id.require' : '缺少參數:文章Id', 'id.number' : '參數錯誤:文章Id', 'content.require' : '文章內容必須填寫', 'content.length' : '文章長度為1~2000個字符', 'title.require' : '文章標題必須填寫', 'title.chsDash' : '文章標題格式錯誤', 'title.length' : '文章標題長度為4~50個字符', } super(rules,message); this.setScene({ 'add' : 'content,title', 'edit': 'id,content,title', 'del' : 'id' }); } } ~~~ 然后可以在驗證方法中制定驗證的場景 ~~~ $data = { 'content' : '文章內容', 'title' : '文章標題' }; const Article = new ArticleValidate(); if(!Article.setSceneName('add').check($data)){ console.log(Article.getError()) } ~~~ 可以單獨為某個場景定義方法(方法的命名規范是`scene`+場景名),并且對某些字段的規則重新設置,例如: * 注意:場景名不區分大小寫,且在調用的時候不能將駝峰寫法轉為下劃線 ~~~ class ArticleValidate extends Validate { constructor() { const rules = { 'id' : 'require|number', 'content' : 'require|length:1,2000', 'title' : 'require|chsDash|length:4,50' } const message = { 'id.require' : '缺少參數:文章Id', 'id.number' : '參數錯誤:文章Id', 'content.require' : '文章內容必須填寫', 'content.length' : '文章長度為1~2000個字符', 'title.require' : '文章標題必須填寫', 'title.chsDash' : '文章標題格式錯誤', 'title.length' : '文章標題長度為4~50個字符', } super(rules,message); } sceneEdit(){ return this.only(['id','content','title']) .append('id','max:10000') .remove('content','length') .remove('title',null) .append('title','require|chsDash|length:4,50') } } ~~~ >[danger] `setSceneName`驗證場景在調用`check`方法以后會被重置,并不會對下一次`check`生效 主要方法說明如下: | 方法名 | 描述 | | --- | --- | | only | 場景需要驗證的字段 | | remove | 移除場景中的字段的部分驗證規則 | | append | 給場景中的字段需要追加驗證規則 |
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看