We always need to add validation on form like registration form, contact form, login form etc. we always prefer to give validation error after page refresh but you can give validation without page refresh. If you use bootstrap then you can use easily validator.js plugin.
validator.js plugin gives client side validation without page refresh. We can use simply. validator.js plugin we can add validation in our PHP project, or any framework like laravel framework, codeigniter framework, symphony framework etc.
In this example i give you how can you give validation for require field, email, minlength etc. you just have to add attribute for validation and it is very customize, you can also set your custom error message using attribute.
So, let's run bellow example or you can check demo. you will find bellow output.