stringCase validator

Check if a string is a lower or upper case one

Options

Use with form field

The HTML attributes are used to set the validator options via the Declarative plugin

Name HTML attribute Type Description
case data-fv-string-case___case String Can be lower (the default value) or upper
message data-fv-string-case___message String The error message

Use with JavaScript module


// You might need to change the importing path
import stringCase from 'formvalidation/validators/stringCase';

const result = stringCase().validate({
    value: ...,
    options: {
        'case': ...,
        message: ...,
    },
});
// result is an object of
// {
//      valid: true or false,
//      message: The error message     
// }

Basic Example

The following form asks user to enter a credit card holder in uppercase:

Module Example

The following snippet shows how to use the stringCase validator with JavaScript module:


// You might need to change the importing path
import stringCase from 'formvalidation/validators/stringCase';

const res1 = stringCase().validate({
    value: 'JOHN SMITH',
    options: {
        'case': 'upper',
        message: 'The name must be in must be in uppercase',
    },
});
// res1.valid === true

const res2 = stringCase().validate({
    value: 'John Smith',
    options: {
        'case': 'lower',
        message: 'The name must be in must be in lowercase',
    },
});
// res2.valid === false