How to use the validator.isEmail function in validator

To help you get started, we’ve selected a few validator examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vpdb / server / src / users / user.api.ts View on Github external
if (!ctx.state.appToken || ctx.state.tokenType !== 'provider') {
			throw new ApiError('Resource only available with provider token.').status(400);
		}
		provider = ctx.state.appToken.provider;

		// validations
		let err = null;
		if (!ctx.request.body.provider_id) {
			err = (err || new ApiError()).validationError('provider_id', 'Identifier at provider is required.');
		} else if (!isString(ctx.request.body.provider_id) && !isNumber(ctx.request.body.provider_id)) {
			err = (err || new ApiError()).validationError('provider_id', 'Identifier at provider must be a number or a string.');
		}
		if (!ctx.request.body.email || !isString(ctx.request.body.email)) {
			err = (err || new ApiError()).validationError('email', 'Email is required.');

		} else if (!validator.isEmail(ctx.request.body.email)) {
			err = (err || new ApiError()).validationError('email', 'Email is invalid.');
		}
		if (!ctx.request.body.username) {
			err = (err || new ApiError()).validationError('username', 'Username is required.');
		} else if (!isString(ctx.request.body.username)) {
			err = (err || new ApiError()).validationError('username', 'Username must be a string.');
		} else if (!/^[0-9a-z ]{3,}$/i.test(UserUtil.removeDiacritics(ctx.request.body.username).replace(/[^0-9a-z ]+/gi, ''))) {
			err = (err || new ApiError()).validationError('username', 'Username must be alphanumeric with at least three characters.', ctx.request.body.username);
		}
		if (ctx.request.body.provider_profile && !isObject(ctx.request.body.provider_profile)) {
			err = (err || new ApiError()).validationError('provider_profile', 'Must be an object.');
		}
		if (err) {
			throw err;
		}
github lzyzsd / androidcn.org / controllers / sign.js View on Github external
nickname = loginname;
  }

  // 验证信息的正确性
  if ([loginname, nickname, pass, rePass, email].some(function (item) { return item === ''; })) {
    ep.emit('prop_err', '信息不完整。');
    return;
  }
  if (loginname.length < 5) {
    ep.emit('prop_err', '用户名至少需要5个字符。');
    return;
  }
  if (!tools.validateId(loginname)) {
    return ep.emit('prop_err', '用户名不合法。');
  }
  if (!validator.isEmail(email)) {
    return ep.emit('prop_err', '邮箱不合法。');
  }
  if (pass !== rePass) {
    return ep.emit('prop_err', '两次密码输入不一致。');
  }
  // END 验证信息的正确性


  User.getUsersByQuery({'$or': [
    {'loginname': loginname},
    {'nickname': nickname},
    {'email': email}
  ]}, {}, function (err, users) {
    if (err) {
      return next(err);
    }
github amida-tech / greyscale / backend / app / controllers / notifications.js View on Github external
var thunkQuery = req.thunkQuery;
    note = yield * checkInsert(req, note);
    var note4insert = _.extend({}, note);
    template = (template || 'default');
    if (!config.notificationTemplates[template]) {
        template = 'default';
    }

    note4insert.note = yield * renderFile(config.notificationTemplates[template].notificationBody, note4insert);
    note4insert = _.pick(note4insert, Notification.insertCols); // insert only columns that may be inserted
    var noteInserted = yield thunkQuery(Notification.insert(note4insert).returning(Notification.id));
    if (parseInt(note.notifyLevel) > 1) { // onsite notification
        socketController.sendNotification(note.userTo);
    }
    var userTo = yield * common.getUser(req, note.userTo);
    if (!vl.isEmail(userTo.email)) {
        throw new HttpError(403, 'Email is not valid: ' + userTo.email); // just in case - I think, it is not possible
    }
    if (typeof note.notifyLevel === 'undefined') {
        note.notifyLevel = userTo.notifyLevel;
    }
    note.subject = note.subject || '';
    note.subject = ejs.render(config.notificationTemplates[template].subject, note);
    note.message = yield * renderFile(config.notificationTemplates[template].emailBody, note);
    var emailOptions = {
        to: {
            name: userTo.firstName,
            surname: userTo.lastName,
            email: userTo.email,
            subject: note.subject
        },
        html: note.message
github FreeFeed / freefeed-server / app / models / user.js View on Github external
static async emailIsValid(email) {
      // email is optional
      if (!email || email.length == 0) {
        return true;
      }

      if (!validator.isEmail(email)) {
        return false;
      }

      const exists = await dbAdapter.existsUserEmail(email);

      if (exists) {
        // email is taken
        return false;
      }

      return true;
    }
github hieuhani / koa-typescript-server-api / src / controllers / authController.ts View on Github external
public async signUp(payload: SignUpPayload): Promise {
    // TODO: Add body validator
    const currentContact = await this.appContext.repositories.contact.findOne({
      where: {
        contact: payload.contact,
      },
    })
    const contactType = validator.isEmail(payload.contact) ? ContactType.email : ContactType.phone
    if (currentContact) {
      let message: string = ''
      if (currentContact.verified) {
        message = `Your email ${payload.contact} has been registered.`
      } else {
        message = `Your email ${payload.contact} has been registered but unverified,
        you might check your inbox to verify your email`
      }
      throw new Error(message)
    }
    const userRepository = this.appContext.repositories.user
    const contactRepository = this.appContext.repositories.contact

    const user = await userRepository.save(userRepository.create({
      firstName: payload.firstName,
      lastName: payload.lastName,
github TryGhost / Ghost-Admin / app / controllers / setup / three.js View on Github external
return this.usersArray.filter(function (user) {
            return validator.isEmail(user || '') && user !== ownerEmail;
        });
    }),
github atomicjolt / react_rails_starter_app / client / js / components / sessions / login.jsx View on Github external
validateEmail(e){
    return this.validate(
      Validator.isEmail(this.refs.email.getValue()),
      { email: "Invalid email" },
      { email: "" }
    );
  }
github chingu-x / chingu-frontend / src / components / DynamicForm / components / utilities.js View on Github external
const isFieldInvalid = (type, value, min, max) => {
  switch (type) {
    case "email": return !isEmail(value);
    case "url": return !isURL(value);
    case "radio": return isEmpty(value);
    case "skill_setter": return !isSkillSetterValid(value);
    default: return !isValid(value, min, max);
  }
}
github ooade / next-apollo-auth / server / models / User.js View on Github external
validator: (v, cb) =>
				cb(validator.isEmail(v), `${v} is not a valid email address`)
		},
github dap-ps / discover / back-end / models / dapps-metadata-model.js View on Github external
validator: function (value) {
                return validator.isEmail(value);
            },
            message: props => `${props.value} is not a valid email!`