[React PropType](https://facebook.github.io/react/docs/reusable-components.html#prop-validation) wrappers around [validator.js functions](https://github.com/chriso/validator.js#validators).
npm install react-validator-prop-typesGreat 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.
js
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:
- email
- url
- fqdn
- ip
- alpha
- numeric
- alphanumeric
- base64
- hexadecimal
- hexColor
- lowercase
- uppercase
- int
- float
- uuid
- date
- creditCard
- json
- multibyte
- ascii
- fullWidth
- halfWidth
- variableWidth
- surrogatePair
- mongoId
- currencyMissing functions ?
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.