<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>

          Joi強大的 JS 數(shù)據(jù)驗證庫

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

          Joi 是用于 JavaScript 的強大的模式描述語言和數(shù)據(jù)驗證器,讓你可以使用簡單、直觀且可讀的語言來描述數(shù)據(jù)。

          示例:

          const Joi = require('joi');
          
          const schema = Joi.object({
              username: Joi.string()
                  .alphanum()
                  .min(3)
                  .max(30)
                  .required(),
          
              password: Joi.string()
                  .pattern(new RegExp('^[a-zA-Z0-9]{3,30}$')),
          
              repeat_password: Joi.ref('password'),
          
              access_token: [
                  Joi.string(),
                  Joi.number()
              ],
          
              birth_year: Joi.number()
                  .integer()
                  .min(1900)
                  .max(2013),
          
              email: Joi.string()
                  .email({ minDomainSegments: 2, tlds: { allow: ['com', 'net'] } })
          })
              .with('username', 'birth_year')
              .xor('password', 'access_token')
              .with('password', 'repeat_password');
          
          
          schema.validate({ username: 'abc', birth_year: 1994 });
          // -> { value: { username: 'abc', birth_year: 1994 } }
          
          schema.validate({});
          // -> { value: {}, error: '"username" is required' }
          
          // Also -
          
          try {
              const value = await schema.validateAsync({ username: 'abc', birth_year: 1994 });
          }
          catch (err) { }
          瀏覽 25
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

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

          手機掃一掃分享

          編輯 分享
          舉報
          <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>
                  人人综合 | 大黄网站在线观看 | 一区二区三区四区五区六区在线 | 韩国TS『人妖av | 肏屄免费视频 |