Giter Site home page Giter Site logo

ember-validator's People

Contributors

alexdiliberto avatar anandts88 avatar jbailey4 avatar panman82 avatar tmeloliveira avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ember-validator's Issues

Issue with hasSpecial pattern validator

I'm trying to use the pattern validator to validate a password. My code looks like this:

  pattern: {
    hasNumber: true,
    hasSpecial: '!@#$&*',
    messages: {
      hasNumber: 'Password should contain at least one number',
      hasSpecial: 'Password should have at least special'
    }
  },

But somehow the it was not working. So went debugging in your add-on's code, and found an issue.

I'm using version 1.2.7, and the issue was on the file ember-validator/addon/mixins/pattern.js.

In this part of the code, at the end of every regex you are doing the test with .test(value).

if (this.options.hasSpecial) {
  if (typeof(this.options.hasSpecial) === 'string') {
    specialTest = new RegExp('(?=.*[' + this.options.hasSpecial + '])').test(value);
  } else if (this.options.hasSpecial.constructor !== RegExp) {
    specialTest = this.options.hasSpecial.test(value);
  } else {
    specialTest = new RegExp('(?=.*[!@$%^&*()-+_=~`{}:;"\'<>,.|?])').test(value);
  }
}

So this is making the variable specialTest a boolean, right ? Because of .test(value) result.

But later on in the code, you are doing this test:

} else if (this.options.hasSpecial && !specialTest.test(value)) {
    this.pushResult(this.options.messages.hasSpecial);
}

And that's causing an error, because !specialTest.test(value) is trying to call the method test in a boolean variable, and not in a regex.

I think the best solution would be to remove the .test(value) from where you define specialTest.

I hope it helps! :)

Add Tests

Placeholder issue here. Currently this addon is untested, Adding tests will allow a safer upgrade path.

Unique property value.

Hi! I've tried to make a custom validation that verifies if the property value is unique in all records on ember-data.
The problem is that the validators don't wait the findAll promises be resolved to validate de object. Any ideas on how can I make this?

Remove dependency on bower

This can easily be done by installing moment.js through npm and changing the path to the moment dist in the index.js file.

`moment.js` date construction using a non-iso string is deprecated

moment.js deprecation warnings may be triggered during date validation. Issues may occur here https://github.com/anandts88/ember-validator/blob/master/addon/mixins/date.js#L49 and here https://github.com/anandts88/ember-validator/blob/master/ember-validator-non-cli.js#L241.

construction using a non-iso string is deprecated (see moment/moment#1407). One possible fix is to just always provide the native new Date(...) constructor as the argument to moment(...).

moment(new Date("2016/01/01"));

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.