Javascript validating empty fields

09 Nov

In fact, although it's crucial that checking user input must be done on the server (e.g., php, .net, ruby, etc.), client-side Java Script can do a lot to make the experience less painful and time consuming.

Java Script runs in the user's browser, therefore it executes immediately.

If the server is busy and takes a while before alerting the user that the form could not be accepted due to errors, users might get quite annoyed and decide not to come back to your otherwise fantastic website.

Thankfully, this rarely happens nowadays, thanks to Java Script.

javascript validating empty fields-58javascript validating empty fields-90javascript validating empty fields-78javascript validating empty fields-82

There are two types of validation: client side validation and server side validation.

As a little refresher from before: Using controlled inputs implies we are storing all the input values in our state.

To indicate whether a particular input is valid, without any additional information as to means a field is invalid.

Instead, use the callback validator to get the raw HTML string, and check if it's the default value generated by the editor, then it's empty field.

I have a verification screen which uses javascript for some validations.