Step 7: validating posts
Validating new posts.
We learnt how to create new posts. Now we may want to add some validation rules for them. You do not want to get empty posts or very short ones.
We're going to use client side validation to check if either title or body are longer than 4 characters, for example.
Also, we want to show some kind of warning when a user tries to create a post that does not pass our super cool validation rule.
Replace:
with
What have we done here?
We have added a property minlength
to both text inputs. This allows HTML5 form controls to check the length of the text we're inputting and to automatically act at elements class for displaying validation errors.
Last updated