An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# react-validator
react-validator in your react appliction is so ease

### Preview
![demo](http://g.recordit.co/l8acHx5Dsc.gif)

### 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|