react-validator-prop-types
v1.1.0
Published
[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).
Downloads
334
Maintainers
Readme
react-validator-prop-types
React PropType wrappers around validator.js functions.
What problem does this solve
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.
Usage
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
Missing 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.
Acknowledgements
Thanks to Chris O'Hara for validator.js.