stringCase validator
Check if a string is a lower or upper case one
Options
Using with form field
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 |
Using with ES6 module
import stringCase from 'formvalidation/dist/es6/validators/stringCase';
const result = stringCase().validate({
value: ...,
options: {
'case': ...,
message: ...,
},
});
Basic example
The following form asks user to enter a credit card holder in uppercase:
ES6 Module Example
The following snippet shows how to use the stringCase validator with ES6 module:
import stringCase from 'formvalidation/dist/es6/validators/stringCase';
const res1 = stringCase().validate({
value: 'JOHN SMITH',
options: {
case: 'upper',
message: 'The name must be in must be in uppercase',
},
});
const res2 = stringCase().validate({
value: 'John Smith',
options: {
case: 'lower',
message: 'The name must be in must be in lowercase',
},
});