Implements a custom input or form validator
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
.github Update `.github/CODEOWNERS` Aug 23, 2018
demo reformat Jul 23, 2018
test reformat Jul 23, 2018
.npmignore Tedium automated v3 element updates. Aug 16, 2018
.travis.yml Only generate types once on Travis Sep 7, 2018 [skip ci] Update contribution guide May 17, 2016 review comments Jul 24, 2018
bower.json Add `bower.json` so that can read the repo. Sep 14, 2018
formatconfig.json Fix formatconfig.json Aug 8, 2018
iron-validator-behavior.js review comments Jul 24, 2018
manifest.json auto-converted by polymer-modulizer Jun 23, 2018
package-lock.json 3.0.1 Sep 14, 2018
wct.conf.json Update WCT config Jun 5, 2018

Published on NPM Build status Published on


Use IronValidatorBehavior to implement a custom input/form validator. Element instances implementing this behavior will be registered for use in elements that implement IronValidatableBehavior.

See: Documentation, Demo.



npm install --save @polymer/iron-validator-behavior

In a Polymer 3 element that is a validator

import {PolymerElement, html} from '@polymer/polymer';
import {mixinBehaviors} from '@polymer/polymer/lib/legacy/class.js';
import {IronValidatorBehavior} from '@polymer/iron-validator-behavior/iron-validator-behavior.js';

class SampleValidator extends mixinBehaviors([IronValidatorBehavior], PolymerElement){
  // This validator only validates strings, and is only valid if
  // the value is "cat".
  function validate(value) {
    return value === 'cat';
customElements.define('sample-validator', SampleValidator);

Using this validator element in an html file

    <script type="module">
      import '../sample-validator.js';
    <sample-validator id="aValidator"></sample-validator>
    <input id="input">
      input.addEventListener('input', function(event) {
        var valid = aValidator.validate(input.value);
        if (valid)
          input.setAttribute('invalid', true);


If you want to send a PR to this element, here are the instructions for running the tests and demo locally:


git clone
cd iron-validator-behavior
npm install
npm install -g polymer-cli

Running the demo locally

polymer serve --npm

Running the tests

polymer test --npm