<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          slime-validatorJavaScript 驗證庫

          聯(lián)合創(chuàng)作 · 2023-09-22 01:18

          slime-validator 是一個基于 Plugin 系統(tǒng)的JavaScript驗證庫,使數(shù)據(jù)驗證變得容易。

          slime-validator 用更少的代碼進行數(shù)據(jù)驗證,比其他工具節(jié)省 20% 以上的代碼,插件系統(tǒng)讓您可以非常簡單地創(chuàng)建自己的驗證規(guī)則,也可以創(chuàng)建復雜的驗證規(guī)則,在瀏覽器和 Nodejs 上均可使用。

          安裝

          使用 npm

           $ npm install slime-validator -save

          瀏覽器

           <script src="${YOUR_PATH}/slime-validator.js"></script>

          基本用法

          對于es模塊

           import Validator from 'slime-validator' // One const V1 = new Validator({ Required:true }) console.log(V1.validate('Hello world')) // Output: null console.log(V1.validate()) // Output: Input is required // Two console.log(Validator.validate({ Required:true }, 'Hello world')) // Output: null console.log(Validator.validate({ Required:true }, null)) // Output: Input is required

          對于 CDN

           <html> <script src="https://unpkg.com/[email protected]/dist/slime-validator.umd.js"></script> <script> let ret = null const v = new window.SlimeValidator({ field: [{ MaxLength: 10 }] }) ret = v.validate({field: '11222222221'}) console.log(JSON.stringify(ret)) </script> <body> </body> </html>

          自定義驗證規(guī)則

           Validator.usePlugin({ tagName: 'IsNotRequired', message(field, value, opts) { return `${field} Check failed` }, validate(field, value, opts) { return false } }, true) // true means to replace the exist rule with the same name. const V7 = new Validator({ field: { IsNotRequired: true } }) console.log(V7.validate({ field: "Something" })) // Output:{ field: 'field Check failed' }

          欲了解更多信息,可以閱讀文檔

          瀏覽 13
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  在线观看亚洲有码 | 手机免费在线看片网址av | 国产裸体视频网站女69 | 日本青青草 | 国产黄色免费观看 |