Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

ember-validators

adopted-ember-addons140.7kMIT5.0.0TypeScript support: included

A collection of EmberJS validators

ember-addon, validations, validators

readme

Ember Validators

Build Status npm version

A collection of EmberJS validators

Compatibility

  • Ember.js v4.8 or above
  • Embroider or ember-auto-import v2

Installation

ember install ember-validators

Looking for help?

If it is a bug please open an issue on GitHub.

Usage

Validators can be individually imported and used as such

import validatePresence from 'ember-validators/presence';
import validateLength from 'ember-validators/length';

validatePresence('foo', { presence: true });
validateLength('foo', { min: 1 });

or via the validate method provided

import { validate } from 'ember-validators';

validate('presence', 'foo', { presence: true });
validate('length', 'foo', { min: 1 });

Validator Method Signature

Each validator has the following signature:

function (value, options, model, attribute) {}

Parameters:

  • value (Mixed):

    The value to validate

  • options (Object):

    A mutable object that holds validation specific options

  • model (Object):

    The model that is being validated

  • attribute (String):

    The attribute that is being validated

Returns:

  • Boolean

    true will be returned if the validation passed

  • Object

    Validation failed and a message should be built with the given attributes

    • type (String):

      The message type

    • value (Mixed):

      The value that was validated

    • context (Object):

      The error message context

    • message (String):

      The error message. If this is specified, use this string as the error message instead of building one.

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.

changelog

Changelog

Release (2025-03-30)

  • ember-validators 5.0.0 (major)

:boom: Breaking Change

:rocket: Enhancement

:bug: Bug Fix

:memo: Documentation

:house: Internal

Committers: 3

v4.1.2 (2022-02-08)

:rocket: Enhancement

Committers: 2

v4.1.0 (2022-01-26)

:rocket: Enhancement

Committers: 1

v4.0.1 (2022-01-06)

:rocket: Enhancement

  • #108 Disable Ember.js v4 scenarios, use npm in GH actions and make CI pass (@SergeAstapov)

:bug: Bug Fix

  • #111 Fix ds-error validator for handling nested objects (@herzzanu)

Committers: 2

v4.0.0

  • [Major]: Remove Moment and Node 10;
    • Remove Node 10 minimum requirement in favor of Node 12
    • removed custom String 'now' argument.
    • remove momentjs
    • Remove precision argument. If you need to compare based on precision, you can use the Intl.DateTimeFormat APIs to hone in on the comparison - { year: 'numeric' }
    • Added locale option. Defaults to en-us when creating date times using Intl.DateTimeFormat API.

v3.0.0

  • Remove node v4

v2.0.0

Pull Requests

v1.2.3

Commits

v1.2.2

Pull Requests

v1.2.1

Commits

  • ef5e5cc date: fix(date): Show correct error message when a date is invalid with a custom format by Offir Golan

v1.2.0

Pull Requests

v1.1.1

Pull Requests

v1.1.0

Pull Requests

v1.0.4

Pull Requests

v1.0.3

Pull Requests

v1.0.2

Pull Requests

  • #52 Use consistent semver of ember-require-module by Lei Zhao

v1.0.1

Pull Requests

v1.0.0

Pull Requests

v0.2.0

Pull Requests

v0.1.2

  • Use ember-require-module

v0.1.1

  • Add Validator documentation

v0.1.0

  • Initial release