4 ms·
Show HN: Form-validation.js – JavaScript form validation library
- VoidWhisperer 6y agoIt is nice that this has no dependencies, but this strikes me as adding a massive amount of boilerplate than what would be normally necessary due to the flexibility.
- p2hari 6y agoThe link for live example does not check for the rule between 3-5 characters for activity name. The rule.js needs to return true for minLength. Just posted it here instead of creating issue, hope it is fine.
- iendeavor 6y agoThanks for reply, I've fix it in the rule.js.
- jeffhandley 6y agoIf you’re looking for something with less boilerplate but still extensive extensibility, check out https://strickland.io https://strickland.io. It also has no dependencies and is pure JavaScript.
- hashamali 6y agoI've been pretty happy with Formik (https://formik.org/docs/overview https://formik.org/docs/overview) for the past few years. Any comparison to this library?
- bilalakbar 6y agoReact Hook Form is gaining traction these days. https://react-hook-form.com/ https://react-hook-form.com/
- iendeavor 6y agoSorry about that I'm not familiar with React ecosystem, so it's hard to me to understand the Formik now. But I've seen that it seems to provide APIs on components to deal with validations. If we just want to validate with route query (which passed from another page and maybe wrong), or validate fields after change page/count, we always need to fill it into form component and then validate it. Hope this post help you well .
- wackget 6y agoSorry but that example code looks confusing as hell. If I saw that code without any context, I really wouldn't be able to tell you what it's doing. Seriously, this is why I hate modern web development. Absolutely everything seems stuffed full of incredibly over-the-top complexity. Libraries like jQuery get a lot of hate because they're not trendy or supposedly impact performance too much, but unless you're serving thousands of visitors simultaneously you really should care more about code readability and maintainability than any of that. At least with something like jQuery validation you can actually understand what the code is doing: $("#myform").validate({ rules: { name: "required", email: { required: true, email: true } }, messages: { name: "Please specify your name", email: { required: "We need your email address to contact you", email: "Your email address must be in the format of name@domain.com" } } });
- majkinetor 6y agoI prefer standards. For example json-editor: https://github.com/json-editor/json-editor https://github.com/json-editor/json-editor It uses json schema validators that have big toolset available.
- oweiler 6y agoJSON Schema is no official standard.
- majkinetor 6y agoFrom practical standpoint, it is.
- somishere 6y agoWhat problem is this resolving? A short intro on the repo might help. Maybe I'm missing the point but I implement validation using standard browser APIs semi-regularly. It used to be painful, these days it is incredibly straightforward. The only place I would potentially consider a validation library is as a side-loaded polyfill for IE. Please explain?
- iendeavor 6y agoThanks for reply, > What problem is this resolving A lot of validation framework doesn't pass `path` (key is not enough in complex situations) to rules to achieve cross-field validation. > ... these days it is incredibly straightforward. I've also read HTML5 standard validation APIs, the APIs is not easy to deal with (at least for me). for example, again, do cross-field validation. > ... polyfill for IE. Sorry about this, form-validation.js is based on modern javascript feature: Proxy (In order to simulate the data-structure of the form you passed in), There is no possible to provide polyfill for Promise Hope this helps you well, I'll add some intro to READMD.md when I am free.
- nsonha 6y agoWow yet another validation library, this one is special because it doesnt care about typescript. Seriously a big part of the problem is to infer type information as you write validators. Anyone can just invent a dsl for type schema. Npm already has heap of these. If we want the schema approach we' probably go with something json-schema based. Have a look at io-ts and runtypes to see what what a modern js validator should look like (again has something to do with typescript)
- bg0 6y agoIf you're looking for something a bit more minimal, check out Pristine: http://pristine.js.org/ http://pristine.js.org/