SHARE
TWEET

Untitled

a guest Jan 11th, 2012 62 Never
  1.     req.onValidationError(function (msg) {
  2.       // put the validation msg if it doesn't exist
  3.       if (_.indexOf(errors, msg) === -1) { errors.push(msg); }
  4.       return this;
  5.     });
  6.     // Validate user input
  7.     try {
  8.       req.check('name', 'Please enter a valid name').len(3,30);
  9.       req.check('comment', 'Please enter a valid comment').len(3,50);
  10.     }
  11.     catch (err) { }
  12.     if (errors.length) {
  13.       req.session.errors = errors;
  14.       res.redirect('/');
  15.     } else {
  16.       render your page
  17.     }
RAW Paste Data
Top