validateTextarea

Function Documentation

This function is a text area validation utility that checks the validity of a given textarea string based on certain criteria.

Function Signature

/**
* @param {string} textarea - The input textarea string to be validated.
* @param {boolean} [isRequired=false] - A boolean flag to determine if the textarea is required (default: false).
* @param {number} [maxLength=50] - The maximum allowed length for the textarea (default: 50).
* @param {string[]} [errorMsg=defaultErrorMsg] - An array of custom error messages for different validation conditions (default: predefined messages).
* @default isRequired boolean: default: false
* @default maxLength number: default: 50
* @example validateTextarea();
* @example validateTextarea();
* @example validateTextarea();
* @description This function returns an object with two properties: 'isValid' (boolean) and 'errorMsg' (string).
* The 'isValid' property indicates if the textarea is valid based on the given criteria, and 'errorMsg' contains the corresponding error message, if any.
*/

Parameters

Return Value

The function returns an object with two properties:

Usage Examples

validateTextarea("Some text content"); // Example 1
// Returns: { isValid: true, errorMsg: null }

validateTextarea("", { isRequired: true }); // Example 2
// Returns: { isValid: false, errorMsg: 'Can not be empty' }

validateTextarea("Very long text...", { isRequired: false, maxLength: 10 }); // Example 3
// Returns: { isValid: false, errorMsg: 'This textarea is too big' }

Note: The examples provided demonstrate how to use the function with different parameters and show the expected return values.