1.0.0-alpha.4 • Published 5 years ago

validated-input v1.0.0-alpha.4

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

NPM Version Build Status Coverage Status paypal

ValidatedInput

A React Component which makes input validation really easy.

Install

npm install --save validated-input

validated-input

Usage

All props are mapped to an input, so just treat the component like a regular input element.

You will need to tell the component how to validate the given value. To make this easy, we have proxied all the validation methods from the amazing validator module.

Here is a couple examples:

import React from 'react';
import ValidatedInput from 'validated-input';

export default function FormExample({ phone, updatePhone, email, updateEmail }) {
  return <div className="form">
    <ValidatedInput
      validate={v => v.isMobilePhone('en-US')}
      type="tel"
      placeholder="Phone Number"
      value={phone}
      onChange={e => updatePhone(e.target.value)}
    />
    <ValidatedInput
      validate={v => v.isEmail()}
      type="email"
      placeholder="Email Address"
      value={email}
      onChange={e => updateEmail(e.target.value)}
      required
    />
  </div>
};

Props for ValidatedInput

All other props are automatically mapped to the inner input element.

NameTypeDefaultDescription
validateFunctionvalidator => trueA function to validate the current value
containerClassNameStringvalidation-containerclass of input container div
errorClassNameStringerrorclass for error