Implements a custom input or form validator

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


Link to this version
ImportedReleased 17 February 2018Other
Framework Support
Polymer 2.0+
Also supported:
Polymer 1 (3.0.1)Polymer 3 (3.0.1)
Browser Compatibility
Install with
bower install --save PolymerElements/iron-validator-behavior"#2.1.0"
Run the above Bower command in your project folder. If you have any issues installing, please contact the author.
Release notes - Version 2.1.0


  • iron-meta#PolymerElements/iron-meta#1 - 2
  • polymer#Polymer/polymer#1.9 - 2