Simple Error validation

I’ve been racking my brains these last couple of days trying to figure out how to do simple (I’m talking really simple, not meteor-accounts, not autoform complexity) validation of forms. Specifically I’m looking to just validate signup details client side (password length, valid email) and server-side, and just simple login validation. I’ve setup a simple schema for Users so along with default Accounts server-side errors I’m also using the schema to validate pretty OK on the server, but I’m having a hard time finding some simple examples that I can look at for how to do this. I’m sure almost every Meteor project out there has some sort of error validation as part of it, why is it so hard to find examples on how to do this without using automated packages? Would appreciate any pointers to repo’s or just general pointers that can help me out.

1 Like

Have you checked out (pun intended) http://docs.meteor.com/#/full/check?

1 Like

Not sure what you mean by “autoform complexity”. It can be as simple as you need it to be. Autoform is a great solution. We use autoform with simpleSchema in every applications which has forms. Saves a lot of time compared to doing validation, validation messages and CRUD by hand.

Basically Meteor is validation agnostic. They don’t dictate how you should do validation, so you are free to roll your own validation or use a library like http://parsleyjs.org/ or others

If you’re allergic to autoform for some reason, you could also accomplish what you’ve stated here rather easily with the user-accounts package.

As noted in their docs

AccountsTemplates.addField({
    _id: 'password',
    type: 'password',
    placeholder: {
        signUp: "At least six characters"
    },
    required: true,
    minLength: 6,
    re: /(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}/,
    errStr: 'At least 1 digit, 1 lowercase and 1 uppercase',
});
1 Like

You can use simple schema to validate your thing. Just do YourSchema.validate(yourDoc).

Or actually you can use the check package if you want some extreme simplicity. But custom error messages might be hard to come by.

1 Like

there are provisions in simpleSchema for custom messages. we use them everywhere. pretty easy to do.

This is great. I really have to swallow my own words here, gave auto form with Simple Schema another go and wow I finally - after spending a significant amount of time validating client and server side, handling forms and errors messages - understand the power of auto form. Have now slowly started transitioning to the classic combo of autoform+SimpleSchema+Collection2.

1 Like