
Client-side validation is a fundamental aspect of web development, vital for delivering user-friendly interfaces and reinforcing the security of online platforms. It involves performing validation checks on the user’s device when filling out forms before sending the data to the server.
Why is it important?
1. It provides instant feedback, making the user’s experience smoother and less error-prone.
2. Reduces server load by minimising unnecessary server requests for invalid data.
3. Enhances security by limiting what the user can input, thereby preventing malicious attacks like SQL injection or cross-site scripting.
Validation types
There are two different types of client-side validation that can be found on the web:
1. Built-in form validation: It uses HTML form validation features, requiring minimal Javascript. This results in better performance than JavaScript validation, although it is less customisable.
2. JavaScript validation: Coded using JavaScript, it offers complete customisation. However, it requires creating everything and may be less performant than built-in validation.
This is where FormFusion comes into play. It leverages everything built-in form validation offers plus extends the list of available validation attributes that can be used. It offers 500+ validation types.
How to use FormFusion for form validation
The FormFusion's Input component builds upon the native HTML input element and enhances it with an expanded range of field types, each associated with a specific validation pattern. You can specify the field type by using the 'type' property.
<Form onSubmit={onSubmit} className="form">
<Input name="name" type="alphabetic" />
<button type="submit">Submit</button>
</Form>
Now when the user enters characters in the input field that are not letters, they get the following message:

This is the default look of FormFusion's form and input components since it is primarily unstyled library. To apply style to the form or input components you can use the same approach as with any html/jsx element, using the className property.
Additionally, for the input component you can also pass a classes property to style the field, label and error elements directly:
<Form onSubmit={onSubmit} className="form"> <Input name="username" type="alphabetic" label="Username" classes={{ field: 'input-field', label: 'input-field__label', error: 'input-field__error-message' }} /> <button type="submit">Submit</button> </Form>

<Form onSubmit={onSubmit} className="form">
<Input name="username"
type="alphabetic"
label="Username"
classes={{
field: 'input-field',
label: 'input-field__label',
error: 'input-field__error-message'
}}
validation={{
patternMismatch: 'Please use letters only. Thank you!'
}}
/>
<button type="submit">Submit</button>
</Form>

Summary
Client-side validation makes forms easier to use and helps keep websites
secure. It checks user input before sending data to the server, improving
user experience and reducing server load. There are two types: built-in
HTML validation (simple and fast) and JavaScript validation (fully
customizable but less performant).
FormFusion combines the best of both worlds, offering 500+ validation
types and easy integration.