React PropType wrappers around validator.js functions.
Great validation libraries already exist, but the default set of React PropTypes is pretty sparse by comparison. This just wraps the popular validator.js library into prop types that support the isRequired
convention.
var ValidatorPropTypes = require('react-validator-prop-types');
React.createClass({
propTypes: {
background: ValidatorPropTypes.hexColor,
email: ValidatorPropTypes.email.isRequired,
username: ValidatorPropTypes.lowercase.isRequired,
}
...
});
The following prop types are available:
- url
- fqdn
- ip
- alpha
- numeric
- alphanumeric
- base64
- hexadecimal
- hexColor
- lowercase
- uppercase
- int
- float
- uuid
- date
- creditCard
- json
- multibyte
- ascii
- fullWidth
- halfWidth
- variableWidth
- surrogatePair
- mongoId
- currency
There's no easy way to wrap validator functions that take multiple, or optional arguments. This is why functions like isMobilePhone
aren't supported (because of the locale
argument). Suggestions for an api for those are encouraged.
Thanks to Chris O'Hara for validator.js.