check-input-patterns
TypeScript icon, indicating that this package has built-in type declarations

2.0.2 • Public • Published

input-patterns

It removes unwish values from a string based on 1 or more regexp patterns.

It is compatible with React

See an example in https://codesandbox.io/s/check-input-patterns-example-593ygr?file=/src/App.js

Usage

import React from "react";
import applyPatterns from "check-input-patterns";

const Input = (props) => {
  return (
    <input
      {...props}
      className={`my-class ${props.className || ""}`}
      value={applyPatterns(props.value.toString(), props.patterns || [])}
      type={props.type || "text"}
      onChange={(e) => {
        const newValue = applyPatterns(
          e.target.value.toString(),
          props.patterns || []
        );

        e.target.value = newValue;

        props.onChange(e);
      }}
    />
  );
};
export default Input;
import { NO_COMMA, NO_DASH, NO_NUMBERS } from "check-input-patterns";
import Input from "./Input";
import { useState } from "react";

export default function App() {
  const [value, setValue] = useState("");

  return (
    <>
      <Input
        patterns={[NO_COMMA, NO_DASH, NO_NUMBERS]}
        value={value}
        onChange={(e) => {
          setValue(e.target.value);
        }}
      />
    </>
  );
}

Readme

Keywords

none

Package Sidebar

Install

npm i check-input-patterns

Weekly Downloads

2

Version

2.0.2

License

MIT

Unpacked Size

8.77 kB

Total Files

15

Last publish

Collaborators

  • franca.josejunior