Forms in Joomla can be validated in two ways: (i) Client-side and (ii) Server-side.
First, you need to add a behavior to your form view template. For Joomla versions from 3.4:
Then, add the form-validate class to your form.
Then, you need to add a validation class to your form field declarations. The following classes are available:
Finally, add the validate class to your submit button. This will cause an onclick handler to be added that validates the whole form. The form will only be submitted if it is valid.
<input type="submit" name="submit" class="validate btn btn-primary"/>