Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Client and server side validation in Meteor JS

So I'm using Meteor's 'methods' to transmit data between the client and server. Is there a recommended pattern for validating data? I've seen SimpleSchema used on the server like this a bit

Lists.schema = new SimpleSchema({
  name: {type: String},
  incompleteCount: {type: Number, defaultValue: 0},
  userId: {type: String, regEx: SimpleSchema.RegEx.Id, optional: true}
});

...

const list = {
  name: 'My list',
  incompleteCount: 3
};
Lists.schema.validate(list);

...which makes sense, is there something I similar I should be using on the client to validate forms? Any extra information would be appreciated as well.

like image 731
J Smith Avatar asked Nov 21 '25 01:11

J Smith


1 Answers

You can use simple-schema to validate arguments in methods when you use Meteor's validated method package.

https://github.com/meteor/validated-method

One advantage to this is that you can validate the args on the client in the method simulation so if there is an error, the method is rejected before it even gets to the server.

You can also use the Meteor's check package (https://docs.meteor.com/api/check.html) as part of your validation.

In terms of validating forms, there are many solutions. An example would be jQuery validation

like image 186
Sean Avatar answered Nov 22 '25 16:11

Sean



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!