• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript validator.isMobilePhone函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中validator.isMobilePhone函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isMobilePhone函数的具体用法?TypeScript isMobilePhone怎么用?TypeScript isMobilePhone使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了isMobilePhone函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1:

        tv4.addFormat("mobile", (data, schema): any => {
            if (validator.isMobilePhone(data, "zh-CN")) {
                return null;
            }

            return 10003;
        });
开发者ID:nick121212,项目名称:blessing,代码行数:7,代码来源:validator.custom.value.ts


示例2: validateQuery

export function validateQuery(body: any): [boolean, any] {
  let result = false,
    query = null,
    tuple: any = UTIL.kvp2tuple(body),
    key: string = tuple[0],
    value: string = tuple[1].toString().trim()

  if (['username', 'handle', 'email', 'mobile'].indexOf(key) < 0) {
    return [result, { code: ERRORS.LOGIN.UNKNOWN_QUERY }]
  } else {
    switch (key) {
      // validate user username
      case 'username':
        if (UTIL.validateUsername(value)) {
          result = true
          query = {username: value}
        } else {
          query = { code: ERRORS.LOGIN.VALID_USER_NAME_REQUIRED }
        }
      break

      // validate user handle
      case 'handle':
        if (UTIL.validateHandle(value)) {
          result = true
          query = {handle: value}
        } else {
          query = { code: ERRORS.LOGIN.VALID_USER_HANDLE_REQUIRED }
        }
      break

      // validate email address
      case 'email':
        if (validator.isEmail(value)) {
          result = true
          query = {email: value}
        } else {
          query = { code: ERRORS.LOGIN.VALID_EMAIL_ADDRESS_REQUIRED }
        }
      break

      // validate mobile phone number
      case 'mobile':
        value = UTIL.normalizeMobile(value)

        if (validator.isMobilePhone(value, CONFIG.DEFAULT_LOCALE)) {
          result = true
          query = {mobile: value}
        } else {
          query = { code: ERRORS.LOGIN.VALID_MOBILE_PHONE_NUMBER_REQUIRED }
        }
      break
    }

    return [result, query]
  }
}
开发者ID:yeegr,项目名称:SingularJS,代码行数:57,代码来源:UserController.ts


示例3: if

}, (username: string, password: string, done: Function) => {
    let params

    if (validator.isEmail(username)) {
      params = {
        email: username
      }
    } else if (validator.isMobilePhone(username, CONFIG.DEFAULT_LOCALE)) {
      params = {
        mobile: username
      }
    } else {
      params = {
        username
      }
    }

    Object.assign(params, {
      status: CONST.STATUSES.PLATFORM.ACTIVE
    })

    Platform
    .findOne({
      username,
      status: CONST.STATUSES.PLATFORM.ACTIVE
    })
    .then((user: IPlatform) => {
      if (user) {
        user.comparePassword(password, (err: Error, isMatch: boolean) => {
          if (err) { return done(err) }
          if (!isMatch) { return done(null, false, {code: ERRORS.LOGIN.PASSWORD_INCORRECT })}
          return done(null, user, 'local')
        })
      } else {
        return done(null, false, { code: ERRORS.LOGIN.USER_NOT_FOUND })
      }
    })
    .catch((err: Error) => {
      return done(err, false)
    })
  })
开发者ID:yeegr,项目名称:SingularJS,代码行数:41,代码来源:platform.ts


示例4:

  result = validator.isInt('sample', isIntOptions);

  result = validator.isJSON('sample');

  let isLengthOptions: ValidatorJS.IsLengthOptions;
  result = validator.isLength('sample', isLengthOptions);
  result = validator.isLength('sample', 3);
  result = validator.isLength('sample', 3, 5);

  result = validator.isLowercase('sample');

  result = validator.isMACAddress('sample');

  result = validator.isMD5('sample');

  result = validator.isMobilePhone('sample', 'ar-DZ');
  result = validator.isMobilePhone('sample', 'ar-SA');
  result = validator.isMobilePhone('sample', 'ar-SY');
  result = validator.isMobilePhone('sample', 'cs-CZ');
  result = validator.isMobilePhone('sample', 'de-DE');
  result = validator.isMobilePhone('sample', 'da-DK');
  result = validator.isMobilePhone('sample', 'el-GR');
  result = validator.isMobilePhone('sample', 'en-AU');
  result = validator.isMobilePhone('sample', 'en-GB');
  result = validator.isMobilePhone('sample', 'en-HK');
  result = validator.isMobilePhone('sample', 'en-IN');
  result = validator.isMobilePhone('sample', 'en-NZ');
  result = validator.isMobilePhone('sample', 'en-US');
  result = validator.isMobilePhone('sample', 'en-CA');
  result = validator.isMobilePhone('sample', 'en-ZA');
  result = validator.isMobilePhone('sample', 'en-ZM');
开发者ID:Crevil,项目名称:DefinitelyTyped,代码行数:31,代码来源:validator-tests.ts


示例5:

 validation: (val: string) => validator.isMobilePhone(val, CONFIG.DEFAULT_LOCALE)
开发者ID:yeegr,项目名称:SingularJS,代码行数:1,代码来源:EventModel.ts


示例6: initTotp

export function initTotp(req: Request, res: Response, next: NextFunction): void {
  let body = req.body,
    UserModel: Model<IUser> = UTIL.getModelFromName(req.routeVar.userType)
  
  if (!body.hasOwnProperty('action')) {
    res.status(400).send({
      code: ERRORS.LOGIN.TOTP_ACTION_REQUIRED
    })
  } else if (!body.hasOwnProperty('type')) {
    res.status(400).send({
      code: ERRORS.LOGIN.TOTP_TYPE_REQUIRED
    })
  } else if (CONST.TOTP_TYPES_ENUM.indexOf(body.type) < 0) {
    res.status(400).send({
      code: ERRORS.LOGIN.TOTP_TYPE_INVALID
    })
  } else if (body.type === CONST.TOTP_TYPES.EMAIL && !validator.isEmail(body.value)) {
    res.status(400).send({
      code: ERRORS.LOGIN.VALID_EMAIL_ADDRESS_REQUIRED
    })
  } else if (body.type === CONST.TOTP_TYPES.SMS && !validator.isMobilePhone(body.value, CONFIG.DEFAULT_LOCALE)) {
    res.status(400).send({
      code: ERRORS.LOGIN.VALID_MOBILE_PHONE_NUMBER_REQUIRED
    })
  } else if (body.action === CONST.USER_ACTIONS.COMMON.UPDATE) {
    let query: any = {}
    query[body.type] = body.value

    UserModel
    .findOne(query)
    .then((data: IUser) => {
      if (!data) {
        return next()
      }

      res.status(200).json({isAvailable: false})
    })
    .catch((err: Error) => {
      res.status(res.statusCode).send()
      console.log(err)
    })
  } else if (body.action === CONST.USER_ACTIONS.COMMON.RESET_PASSWORD) {
    let query: any = {}
    query[body.type] = body.value

    UserModel
    .findOne(query)
    .then((data: IUser) => {
      if (!data) {
        res.status(404).json({ code: ERRORS.LOGIN.USER_NOT_FOUND })
        return false
      }

      next()
    })
    .catch((err: Error) => {
      res.status(res.statusCode).send()
      console.log(err)
    })
  } else {
    next()
  }
}
开发者ID:yeegr,项目名称:SingularJS,代码行数:63,代码来源:UserController.ts


示例7:

  result = validator.isInt('sample', isIntOptions);

  result = validator.isJSON('sample');

  let isLengthOptions: ValidatorJS.IsLengthOptions;
  result = validator.isLength('sample', isLengthOptions);
  result = validator.isLength('sample', 3);
  result = validator.isLength('sample', 3, 5);

  result = validator.isLowercase('sample');

  result = validator.isMACAddress('sample');

  result = validator.isMD5('sample');

  result = validator.isMobilePhone('sample', 'en-US');

  result = validator.isMongoId('sample');

  result = validator.isMultibyte('sample');

  result = validator.isNull('sample');

  result = validator.isNumeric('sample');

  result = validator.isSurrogatePair('sample');

  let isURLOptions: ValidatorJS.IsURLOptions;
  result = validator.isURL('sample');
  result = validator.isURL('sample', isURLOptions);
开发者ID:korve,项目名称:DefinitelyTyped,代码行数:30,代码来源:validator-tests.ts


示例8:

  let isLengthOptions: ValidatorJS.IsLengthOptions = {};
  result = validator.isLength('sample', isLengthOptions);
  result = validator.isLength('sample', 3);
  result = validator.isLength('sample', 3, 5);

  result = validator.isLowercase('sample');

  result = validator.isMACAddress('sample');

  result = validator.isMD5('sample');

  result = validator.isMimeType('sample');

  let isMobilePhoneOptions: ValidatorJS.IsMobilePhoneOptions = {};
  result = validator.isMobilePhone('sample', 'any', isMobilePhoneOptions);
  result = validator.isMobilePhone('sample', 'ar-AE');
  result = validator.isMobilePhone('sample', 'ar-DZ');
  result = validator.isMobilePhone('sample', 'ar-EG');
  result = validator.isMobilePhone('sample', 'ar-JO');
  result = validator.isMobilePhone('sample', 'ar-SA');
  result = validator.isMobilePhone('sample', 'ar-SY');
  result = validator.isMobilePhone('sample', 'be-BY');
  result = validator.isMobilePhone('sample', 'bg-BG');
  result = validator.isMobilePhone('sample', 'cs-CZ');
  result = validator.isMobilePhone('sample', 'de-DE');
  result = validator.isMobilePhone('sample', 'da-DK');
  result = validator.isMobilePhone('sample', 'el-GR');
  result = validator.isMobilePhone('sample', 'en-AU');
  result = validator.isMobilePhone('sample', 'en-GB');
  result = validator.isMobilePhone('sample', 'en-HK');
开发者ID:Jeremy-F,项目名称:DefinitelyTyped,代码行数:30,代码来源:validator-tests.ts


示例9: function

    app.get('/validate-user', function (req, res) {
        if (!_.isUndefined(req.query.username)) {
            if (validator.isAlphanumeric(req.query.username)) {
                user.validateUser(req.query).then(function (isExisted: boolean) {
                    var result = (isExisted) ?
                        {
                            isNotValid: true,
                            rule: 'existed',
                            message: 'Username is existed'
                        } :
                        {
                            isNotValid: false
                        };
                    res.json(result);
                });
            } else {
                res.json({
                    isNotValid: true,
                    rule: 'alphanumberic',
                    message: 'Username contains special character or space'
                });
            }
        }
        if (!_.isUndefined(req.query.email)) {
            if (validator.isEmail(req.query.email)) {
                user.validateUser(req.query).then(function (isExisted: boolean) {
                    var result = (isExisted) ?
                        {
                            isNotValid: true,
                            rule: 'existed',
                            message: 'Email is existed'
                        } :
                        {
                            isNotValid: false
                        };
                    res.json(result);
                });
            } else {
                res.json({
                    isNotValid: true,
                    rule: 'email',
                    message: 'Email is wrong format'
                });
            }
        }
        if (!_.isUndefined(req.query.phone)) {
            if (!validator.isMobilePhone(req.query.phone, 'vi-VN')) {
                res.json({
                    isNotValid: true,
                    rule: 'phone-number',
                    message: 'Phone number is wrong format'
                });
            } else {
                res.json({
                    isNotValid: false
                });
            }
        }
        if (!_.isUndefined(req.query.password)) {
            if (!validator.isAlphanumeric(req.query.password)) {
                res.json({
                    isNotValid: true,
                    rule: 'alphanumberic',
                    message: 'Password is wrong format'
                });
            } else {
                res.json({
                    isNotValid: false
                });
            }

        }
    });
开发者ID:ttlpta,项目名称:nodejs-ecomerce,代码行数:73,代码来源:userController.ts



注:本文中的validator.isMobilePhone函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript validator.isNumeric函数代码示例发布时间:2022-05-25
下一篇:
TypeScript validator.isLength函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap