https://github.com/febobo/react-validator
react-validator in your react appliction is so ease
https://github.com/febobo/react-validator
Last synced: 10 months ago
JSON representation
react-validator in your react appliction is so ease
- Host: GitHub
- URL: https://github.com/febobo/react-validator
- Owner: febobo
- Created: 2017-09-15T09:09:12.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-09-28T08:08:47.000Z (over 8 years ago)
- Last Synced: 2024-11-07T05:12:15.353Z (over 1 year ago)
- Language: JavaScript
- Size: 8.79 KB
- Stars: 4
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# react-validator
react-validator in your react appliction is so ease
### Preview

### Install
```
npm install react-validator-ease` or `yarn install react-validator-ease
```
### Usege
- link
```bash
const ReactValidator from 'react-valid-ease'
```
- es5
```js
componentWillMount: function() {
this.validator = new ReactValidator();
},
```
- es6
```js
constructor() {
this.validator = new ReactValidator();
}
```
- jsx
```jsx
render: function() {
return (
Example Form
email
{this.validator.message('email', this.state.email, 'required|email','',{
required: 'email不能为空',
email: 'email 格式不正确'
})}
required
{this.validator.message('required', this.state.required, 'required|max:12|min:6','',{
default: 'required不能为空',
min: '不能少于6个字符',
max: '不能大于12个字符'
})}
Submit
);
}
```
* The message method have five arguments
- Field: Name: A unique string
- Value: Current field value
- Rules: Rules string, support use pipe separated
- Custom ClassName: ClassName string, your can custom you errorMessage style
- Custom Error Message: your can custom you errorMessage text
### Rules
Examples: `require|min:6|min:12`
|Rule|Description|
|---|---|
|require|must be a valid input|
|email|must be a valid email address|
|max|may not be greater than max characters|
|min|may not be greater than mix characters|
|number|must be a number|
|phone|must be a valid phone number|
|url|must be a valid url|
|accepted|must be a valid Boolean|