當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript validator.isMobilePhone函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。