3. Input Validations
User Manual: Input Validation in Low Code Web Form Designer
Introduction
This user manual provides detailed instructions on how to perform input validation within a low-code web form designer. Input validation is essential to ensure that the data entered by users meets the required format, constraints, and business rules before being processed or stored. This guide will cover various validation techniques, including basic validations, advanced conditional validations, custom validation logic, and examples for each.
Table of Contents
- Understanding Input Validation
- Types of Input Validation
- Basic Validation Techniques
- Advanced Validation Techniques
- Custom Validation Logic
- Examples of Input Validation
- Testing and Debugging Validations
- Conclusion
1. Understanding Input Validation
Input validation is the process of verifying that the data entered by users in a web form meets specific criteria. This can include checking for the correct data type, ensuring required fields are not empty, and validating that inputs conform to a particular format or range.
Importance of Input Validation
- Data Integrity: Ensures that only valid and correctly formatted data is processed or stored.
- Security: Helps prevent security vulnerabilities such as SQL injection or XSS attacks by validating and sanitizing user inputs.
- User Experience: Provides immediate feedback to users, allowing them to correct errors before submitting the form.
2. Types of Input Validation
Basic Validation
- Required Fields: Ensures that mandatory fields are not left empty.
- Data Type Validation: Verifies that the input matches the expected data type (e.g., numbers, text, dates).
- Length Validation: Checks that the input does not exceed or fall short of a specified length.
Advanced Validation
- Regular Expression (Regex) Validation: Uses patterns to validate complex input formats such as email addresses, phone numbers, or postal codes.
- Range Validation: Ensures that numerical or date inputs fall within a specified range.
- Conditional Validation: Applies validation rules based on other field values or conditions.
Custom Validation
- Custom Logic: Implement bespoke validation rules using custom scripts or functions.
- Asynchronous Validation: Validates inputs against external data sources or APIs in real time.
3. Basic Validation Techniques
Step 1: Setting Up Required Fields
- Open the Form Designer:
- Navigate to the web form where you want to apply input validation.
-
Select the field that you want to make mandatory.
-
Enable Required Field Validation:
- In the field properties panel, toggle the "Required" option to enable validation.
-
Optionally, customize the error message that will appear if the field is left empty.
-
Save and Test:
- Save the form and test it by attempting to submit it with the required field left blank.
Step 2: Applying Data Type Validation
- Select the Input Field:
-
Choose the input field (e.g., text box, number field) that requires data type validation.
-
Configure Data Type:
- In the field properties, select the appropriate data type (e.g., number, text, date).
-
For numeric fields, specify whether to allow decimals or enforce integer-only values.
-
Error Handling:
-
Customize the error message that will be displayed if the input does not match the expected data type.
-
Save and Test:
- Save the form and input data that violates the data type rules to see if the validation works as expected.
Step 3: Enforcing Length Validation
- Open the Field Properties:
-
Select the field that requires length validation.
-
Set Length Constraints:
-
Define the minimum and maximum length allowed for the input (e.g., a password must be between 8 and 16 characters).
-
Error Message Configuration:
-
Set a custom error message for when the input length is invalid.
-
Save and Test:
- Save the form and enter data that is too short or too long to test the validation.
4. Advanced Validation Techniques
Step 1: Implementing Regex Validation
- Select the Input Field:
-
Choose the field where you want to apply regex validation (e.g., email address, phone number).
-
Add Regex Pattern:
- In the field properties, find the "Validation" or "Pattern" option.
-
Enter a regex pattern that matches the required format (e.g.,
^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}$for an email). -
Customize Error Messages:
-
Provide a user-friendly error message that explains what is wrong with the input.
-
Save and Test:
- Save the form and test it with various inputs to ensure the regex validation works correctly.
Step 2: Applying Range Validation
- Select the Numeric or Date Field:
-
Choose the field that requires range validation (e.g., age, date of birth).
-
Set the Valid Range:
- In the field properties, define the minimum and maximum allowable values.
-
For dates, you can specify a start and end date range.
-
Configure Error Messages:
-
Customize the error message for when the input falls outside the allowed range.
-
Save and Test:
- Save the form and input data outside the specified range to verify the validation.
Step 3: Creating Conditional Validation
- Select the Conditional Field:
-
Choose the field that should be validated conditionally based on another field's value.
-
Define the Condition:
-
In the validation settings, create a rule that applies validation only if certain conditions are met (e.g., "If 'Country' is 'USA', then 'State' is required").
-
Set Up Error Handling:
-
Write a clear error message that indicates why the validation failed.
-
Save and Test:
- Save the form and test the conditional validation by changing the trigger conditions.
5. Custom Validation Logic
Step 1: Writing Custom Validation Scripts
- Access the Custom Validation Editor:
- In the form designer, select the field where you want to add custom validation.
-
Open the "Custom Validation" section.
-
Write the Validation Script:
- Use the platform’s scripting language (e.g., JavaScript) to write a validation function.
-
Example:
javascript function validatePassword(input) { if (input.length < 8) { return "Password must be at least 8 characters long."; } if (!/[A-Z]/.test(input)) { return "Password must contain at least one uppercase letter."; } if (!/[0-9]/.test(input)) { return "Password must contain at least one number."; } return true; // Return true if validation passes } -
Apply the Script:
-
Link the custom validation function to the field and specify when it should be triggered (e.g., on blur, on submit).
-
Save and Test:
- Save the form and test the custom validation by entering both valid and invalid inputs.
Step 2: Implementing Asynchronous Validation
- Select the Field for Validation:
-
Choose the field where asynchronous validation is needed (e.g., username availability check).
-
Set Up API Integration:
- In the validation settings, configure an API call that checks the input against an external system.
-
Example: Validate that a username is not already taken by querying the database.
-
Handle the API Response:
- Write logic to process the API response and display appropriate error messages.
-
Example:
javascript function checkUsernameAvailability(username) { fetch(`https://api.example.com/check-username?username=${username}`) .then(response => response.json()) .then(data => { if (data.available) { return true; } else { return "Username is already taken."; } }); } -
Save and Test:
- Save the form and test the asynchronous validation by entering different usernames.
6. Examples of Input Validation
Example 1: Email Validation
- Field: Email Address
- Validation Type: Regex Validation
- Pattern:
^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}$ - Error Message: "Please enter a valid email address."
Example 2: Age Validation
- Field: Age
- Validation Type: Range Validation
- Range: 18 to 65
- Error Message: "Age must be between 18 and 65."
Example 3: Password Validation
- Field: Password
- Validation Type: Custom Validation
- Script: ```javascript function validatePassword(input) { if (input.length < 8) { return "Password must be at least 8 characters long."; } if (!/[A-Z]/.test(input)) { return "Password must contain at least one uppercase letter."; } if (!/[0-9]/.test(input)) { Input validation summary The platform includes robust validation capabilities to ensure data integrity and consistency:
- Field-Level Validation: Validate individual fields for format, range, and required conditions.
- Form-Level Validation: Implement checks that apply to the entire form before submission.
- Custom Validation Rules: Create custom validation scripts using expressions or code snippets.
- Real-Time Validation: Provide instant feedback to users as they enter data.
- Error Messaging: Display custom error messages when validation fails.
- Cross-Field Validation: Validate data based on conditions between multiple fields.
FlexiFlow