Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/tiendq/filtered-input

A simple input that only accepts characters based on a Regex pattern
https://github.com/tiendq/filtered-input

es6 form npm react validation

Last synced: about 2 months ago
JSON representation

A simple input that only accepts characters based on a Regex pattern

Awesome Lists containing this project

README

        

# filtered-input
A simple input that only accepts characters based on a Regex pattern. My intention is just limiting characters could be entered into an input field, no masking capability, no formatting etc.

## Usage
Simply install and import component like below code:

`yarn add filtered-input`

```js
import React from 'react';
import ReactDOM from 'react-dom';
import FilteredInput from 'filtered-input';

ReactDOM.render(


, document.getElementById("root")
);
```

### Properties
Besides below properties, you could add any HTML input attributes as usual except `value`.

#### `type`
Input type e.g. text, email. `Required`

#### `filterPattern`
A RegEx pattern to filter which characters are allowed to enter in the input. `Required`

#### `validatePattern`
A RegEx pattern to validate current input value, relied on [validator.matches](https://github.com/chriso/validator.js). `Required`

#### `onChange`
Called on change event with current `value` and validation result `passed` if `validatePattern` is supplied. You could use it to get input value or change input control appearance based its validation state.

#### `customFormatter`
Called with current `value` to provide formatting capability e.g. 5000 becomes 5,000

## Examples
1. Run `yarn start` from `examples` folder
2. Visit `http://localhost:8080`

Copyright (c) 2016 Tien Do

MIT License