stringCase validator

Check if a string is a lower or upper case one

Options

Using with form field
The HTML attributes are used to set the validator options via the Declarative plugin
NameHTML attributeTypeDescription
casedata-fv-string-case___caseStringCan be lower (the default value) or upper
messagedata-fv-string-case___messageStringThe error message
Using the ES6 module
// You might need to change the importing path
import { stringCase } from '/vendors/@form-validation/cjs/validator-string-case';
const result = stringCase().validate({
value: ...,
options: {
'case': ...,
message: ...,
},
});
// result is an object of
// {
// valid: true or false,
// message: The error message
// }
Using the npm package
  • Install the validator package:
$ npm install @form-validation/validator-string-case
  • Use the stringCase validator:
import { stringCase } from '@form-validation/validator-string-case';
const result = stringCase().validate({
value: ...,
options: {
'case': ...,
message: ...,
},
});

Basic example

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

NPM package example

The following snippet shows how to use the stringCase validator with the npm package:
import { stringCase } from '@form-validation/validator-string-case';
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

Changelog

v2.1.0
  • The validator doesn't work properly if the message property isn't defined
v2.0.0
  • Add the npm package