String schema
A function which creates a parsing rule to ensure that a given value is a string.
Arguments
- (Optional): A list of modifiers
min
: Learn more.max
: Learn more.email
: Learn more.custom
: Learn more.
- (Optional): A custom object with error messages to be displayed when validation fails or there are type errors.
Example
import { string } from '@nordic-ui/validathor';
const stringRule = string(undefined, 'Value must be a string');
try {
const parsedValue = stringRule.parse('Hello world');
console.log('Parsed value:', parsedValue);
} catch (error) {
console.error('Parsing failed:', error.message);
}