adopted-ember-addons / ember-cp-validations

Ember computed property based validations
https://adopted-ember-addons.github.io/ember-cp-validations/
BSD 3-Clause "New" or "Revised" License
442 stars 174 forks source link

add a special case for default url format validation #595

Open KeranChen opened 6 years ago

KeranChen commented 6 years ago

Environment

Steps to Reproduce

The default format validator for url will return false for the shortened urls from our company's tiny url generator. (eg. http://bburl/abcd), so I want to add a special case to the default url format validator. I wonder whether you could add that special case to the default url format validator? After I upgrade the ember-cp-validations to 4.0.0-beta.1, I find a working solution, which is to create a customized validator.

export default BaseValidator.extend({
    validate(value) {
        const result = this.test('format', value, {
            type: 'url',
            allowBlank: true
        });
        const bburl = /^(https?:\/\/bburl)/;
        if (result.isValid || bburl.test(value)) {
            return true;
        } else {
            return 'Has to be in a valid URL format';
        }
    }
});

I wonder whether you could make the change on your side, if not, what is your suggestion on this issue? Thank you!

onumossn commented 6 years ago

Would it be possible to expand the regex to include urls that don't have top level domains? I don't think that is required for a url to be valid.

leondmello commented 6 years ago

@offirgolan Do you have a preferred direction to resolve this one. We would be happy to submit a fix if you had an inclination towards a particular solution.