O
O
Odisseya2018-03-26 16:18:33
JavaScript
Odisseya, 2018-03-26 16:18:33

Form validation on the client: html5+js || js-bike || jQuery plugins?

Guys, tell me how you usually validate form data on the client *?
*We do not affect the method of sending data and server validation.

Challenge: realtime data validation (i.e. validation on entry, not on form submission) and universality of approach for fast reuse and ease of support. Field types are typical for requests from landing pages.

  1. HTML5 + JS-bicycle - where js is used for cross-browser compatibility and expanding native functionality (Russian-language tooltips showing several errors at once, realtime validation, advanced mask capabilities).
  2. jQuery/JS library - like jqueryvalidation.org.
  3. Only the JS-bicycle is its own script with checks.


***
An additional level of complexity: what do you use for masks and autocomplete - self-writing or libraries?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Simonov, 2018-03-26
@SimasikS

The server describes the validation rules for models. Then in js, validation is done according to the rules from the server,
roughly speaking something like this

validationRules = [{rule : "length > 20", error: "Error"}]
textField.on("change", (element) => {
  foreach(var rule in validationRules){
   if (!element.Valid(rule.rule)){
    element.Errors.Push(rule.Error);
   }
  }
})

Galimenko written, pseudo-code, but you can understand the essence

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question