Merge pull request #115 from christianalfoni/validation-fix

Removed 'required' check from validations
This commit is contained in:
Christian Alfoni 2015-04-29 12:56:43 +02:00
commit f568ac5970
13 changed files with 1142 additions and 165 deletions

File diff suppressed because one or more lines are too long

1
release/formsy-react.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -35,18 +35,6 @@ describe('Rules: equals', function() {
TestInput = isValid = isInvalid = form = null;
});
it('should fail with undefined', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: undefined}});
expect(isValid).not.toHaveBeenCalled();
});
it('should fail with null', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: null}});
expect(isValid).not.toHaveBeenCalled();
});
it('should fail when the value is not equal', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 'foo'}});
@ -59,4 +47,22 @@ describe('Rules: equals', function() {
expect(isValid).toHaveBeenCalled();
});
it('should fail with an undefined', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: undefined}});
expect(isValid).not.toHaveBeenCalled();
});
it('should fail with a null', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: null}});
expect(isValid).not.toHaveBeenCalled();
});
it('should fail with a number', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 42}});
expect(isValid).not.toHaveBeenCalled();
});
});

View File

@ -35,22 +35,44 @@ describe('Rules: hasValue', function() {
TestInput = isValid = isInvalid = form = null;
});
it('should fail with undefined', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: undefined}});
expect(isValid).not.toHaveBeenCalled();
});
it('should fail with null', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: null}});
expect(isValid).not.toHaveBeenCalled();
});
it('should pass with a string', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 'myValue'}});
expect(isValid).toHaveBeenCalled();
});
it('should fail with an undefined', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: undefined}});
expect(isValid).not.toHaveBeenCalled();
});
it('should fail with a null', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: null}});
expect(isValid).not.toHaveBeenCalled();
});
it('should pass with a number', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 42}});
expect(isValid).toHaveBeenCalled();
});
/* ToDo:
it('should pass with an empty string', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: ''}});
expect(isValid).toHaveBeenCalled();
});
it('should pass with a zero', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 0}});
expect(isValid).toHaveBeenCalled();
});
*/
});

View File

@ -35,13 +35,25 @@ describe('Rules: isAlpha', function() {
TestInput = isValid = isInvalid = form = null;
});
it('should fail with undefined', function () {
it('should pass with a string is only latin letters', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 'myValue'}});
expect(isValid).toHaveBeenCalled();
});
it('should fail with a string with numbers', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 'myValue 42'}});
expect(isValid).not.toHaveBeenCalled();
});
it('should fail with an undefined', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: undefined}});
expect(isValid).not.toHaveBeenCalled();
});
it('should fail with null', function () {
it('should fail with a null', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: null}});
expect(isValid).not.toHaveBeenCalled();
@ -49,14 +61,14 @@ describe('Rules: isAlpha', function() {
it('should fail with a number', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 123}});
TestUtils.Simulate.change(input, {target: {value: 42}});
expect(isValid).not.toHaveBeenCalled();
});
it('should pass with a string', function () {
it('should fail with an empty string', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: ''}});
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 'myValue'}});
expect(isValid).toHaveBeenCalled();
});
});

View File

@ -47,4 +47,28 @@ describe('Rules: isEmail', function() {
expect(isValid).toHaveBeenCalled();
});
it('should fail with an undefined', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: undefined}});
expect(isValid).not.toHaveBeenCalled();
});
it('should fail with a null', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: null}});
expect(isValid).not.toHaveBeenCalled();
});
it('should fail with a number', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 42}});
expect(isValid).not.toHaveBeenCalled();
});
it('should fail with an empty string', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: ''}});
expect(isValid).not.toHaveBeenCalled();
});
});

View File

@ -0,0 +1,74 @@
var React = require('react/addons');
var TestUtils = React.addons.TestUtils;
var Formsy = require('./../src/main.js');
describe('Rules: isEmptyString', function() {
var TestInput, isValid, form, input;
beforeEach(function() {
isValid = jasmine.createSpy('valid');
TestInput = React.createClass({
mixins: [Formsy.Mixin],
updateValue: function (event) {
this.setValue(event.target.value);
},
render: function () {
if (this.isValid()) {
isValid();
}
return <input value={this.getValue()} onChange={this.updateValue}/>
}
});
form = TestUtils.renderIntoDocument(
<Formsy.Form>
<TestInput name="foo" validations="isEmptyString"/>
</Formsy.Form>
);
input = TestUtils.findRenderedDOMComponentWithTag(form, 'INPUT');
});
afterEach(function() {
TestInput = isValid = isInvalid = form = null;
});
it('should fail with non-empty string', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 'asd'}});
expect(isValid).not.toHaveBeenCalled();
});
it('should pass with an empty string', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: ''}});
expect(isValid).toHaveBeenCalled();
});
it('should fail with a undefined', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: undefined}});
expect(isValid).not.toHaveBeenCalled();
});
it('should fail with a null', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: null}});
expect(isValid).not.toHaveBeenCalled();
});
it('should fail with a number', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 123}});
expect(isValid).not.toHaveBeenCalled();
});
it('should fail with a zero', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 0}});
expect(isValid).not.toHaveBeenCalled();
});
});

View File

@ -20,55 +20,104 @@ describe('Rules: isLength', function() {
return <input value={this.getValue()} onChange={this.updateValue}/>
}
});
form = TestUtils.renderIntoDocument(
<Formsy.Form>
<TestInput name="foo" validations="isLength:3"/>
</Formsy.Form>
);
input = TestUtils.findRenderedDOMComponentWithTag(form, 'INPUT');
});
afterEach(function() {
TestInput = isValid = isInvalid = form = null;
});
it('should fail with undefined', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: undefined}});
expect(isValid).not.toHaveBeenCalled();
describe('isLength:3', function() {
beforeEach(function() {
form = TestUtils.renderIntoDocument(
<Formsy.Form>
<TestInput name="foo" validations="isLength:3"/>
</Formsy.Form>
);
input = TestUtils.findRenderedDOMComponentWithTag(form, 'INPUT');
});
it('should fail with a string too small', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 'hi'}});
expect(isValid).not.toHaveBeenCalled();
});
it('should fail with a string too long', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 'foo bar'}});
expect(isValid).not.toHaveBeenCalled();
});
it('should pass with the right length', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 'sup'}});
expect(isValid).toHaveBeenCalled();
});
it('should fail with an undefined', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: undefined}});
expect(isValid).not.toHaveBeenCalled();
});
it('should fail with null', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: null}});
expect(isValid).not.toHaveBeenCalled();
});
it('should fail with a number', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 123}});
expect(isValid).not.toHaveBeenCalled();
});
});
it('should fail with null', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: null}});
expect(isValid).not.toHaveBeenCalled();
});
describe('isLength:0', function() {
it('should fail with a number', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 123}});
expect(isValid).not.toHaveBeenCalled();
});
beforeEach(function() {
form = TestUtils.renderIntoDocument(
<Formsy.Form>
<TestInput name="foo" validations="isLength:0"/>
</Formsy.Form>
);
it('should fail with a string too small', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: "hi"}});
expect(isValid).not.toHaveBeenCalled();
});
input = TestUtils.findRenderedDOMComponentWithTag(form, 'INPUT');
});
it('should fail with a string too long', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: "foo bar"}});
expect(isValid).not.toHaveBeenCalled();
});
it('should fail with a string too long', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 'foo bar'}});
expect(isValid).not.toHaveBeenCalled();
});
it('should pass with empty string', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: ''}});
expect(isValid).toHaveBeenCalled();
});
it('should fail with undefined', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: undefined}});
expect(isValid).not.toHaveBeenCalled();
});
it('should fail with null', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: null}});
expect(isValid).not.toHaveBeenCalled();
});
it('should fail with a number', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 123}});
expect(isValid).not.toHaveBeenCalled();
});
it('should pass with the right length', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 'sup'}});
expect(isValid).toHaveBeenCalled();
});
});

View File

@ -35,18 +35,6 @@ describe('Rules: isNumeric', function() {
TestInput = isValid = isInvalid = form = null;
});
it('should fail with undefined', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: undefined}});
expect(isValid).not.toHaveBeenCalled();
});
it('should fail with null', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: null}});
expect(isValid).not.toHaveBeenCalled();
});
it('should fail with a string', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 'myValue'}});
@ -55,19 +43,37 @@ describe('Rules: isNumeric', function() {
it('should pass with a number as string', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: '123'}});
TestUtils.Simulate.change(input, {target: {value: '42'}});
expect(isValid).toHaveBeenCalled();
});
it('should pass with an int', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 123}});
TestUtils.Simulate.change(input, {target: {value: 42}});
expect(isValid).toHaveBeenCalled();
});
it('should pass with a float', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 1.23}});
TestUtils.Simulate.change(input, {target: {value: Math.PI}});
expect(isValid).toHaveBeenCalled();
});
it('should fail with an undefined', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: undefined}});
expect(isValid).not.toHaveBeenCalled();
});
it('should fail with a null', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: null}});
expect(isValid).not.toHaveBeenCalled();
});
it('should pass with a zero', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 0}});
expect(isValid).toHaveBeenCalled();
});

View File

@ -35,24 +35,6 @@ describe('Rules: isWords', function() {
TestInput = isValid = isInvalid = form = null;
});
it('should fail with undefined', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: undefined}});
expect(isValid).not.toHaveBeenCalled();
});
it('should fail with null', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: null}});
expect(isValid).not.toHaveBeenCalled();
});
it('should fail with a number', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 123}});
expect(isValid).not.toHaveBeenCalled();
});
it('should pass with a 1 word', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 'sup'}});
@ -65,4 +47,28 @@ describe('Rules: isWords', function() {
expect(isValid).toHaveBeenCalled();
});
it('should fail with a string with numbers', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 'myValue 42'}});
expect(isValid).not.toHaveBeenCalled();
});
it('should fail with an undefined', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: undefined}});
expect(isValid).not.toHaveBeenCalled();
});
it('should fail with a null', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: null}});
expect(isValid).not.toHaveBeenCalled();
});
it('should fail with a number', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 42}});
expect(isValid).not.toHaveBeenCalled();
});
});

View File

@ -35,24 +35,6 @@ describe('Rules: maxLength', function() {
TestInput = isValid = isInvalid = form = null;
});
it('should fail with undefined', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: undefined}});
expect(isValid).not.toHaveBeenCalled();
});
it('should fail with null', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: null}});
expect(isValid).not.toHaveBeenCalled();
});
it('should fail with a number', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 123}});
expect(isValid).not.toHaveBeenCalled();
});
it('should pass when a string\'s length is smaller', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 'hi'}});
@ -71,4 +53,28 @@ describe('Rules: maxLength', function() {
expect(isValid).not.toHaveBeenCalled();
});
it('should pass with an empty string', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: ''}});
expect(isValid).toHaveBeenCalled();
})
it('should fail with an undefined', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: undefined}});
expect(isValid).not.toHaveBeenCalled();
});
it('should fail with a null', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: null}});
expect(isValid).not.toHaveBeenCalled();
});
it('should fail with a number', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 123}});
expect(isValid).not.toHaveBeenCalled();
});
});

View File

@ -20,55 +20,110 @@ describe('Rules: minLength', function() {
return <input value={this.getValue()} onChange={this.updateValue}/>
}
});
form = TestUtils.renderIntoDocument(
<Formsy.Form>
<TestInput name="foo" validations="minLength:3"/>
</Formsy.Form>
);
input = TestUtils.findRenderedDOMComponentWithTag(form, 'INPUT');
});
afterEach(function() {
TestInput = isValid = isInvalid = form = null;
});
it('should fail with undefined', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: undefined}});
expect(isValid).not.toHaveBeenCalled();
describe('minLength:3', function() {
beforeEach(function() {
form = TestUtils.renderIntoDocument(
<Formsy.Form>
<TestInput name="foo" validations="minLength:3"/>
</Formsy.Form>
);
input = TestUtils.findRenderedDOMComponentWithTag(form, 'INPUT');
});
it('should fail when a string\'s length is smaller', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 'hi'}});
expect(isValid).not.toHaveBeenCalled();
});
it('should pass when a string\'s length is equal', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 'bar'}});
expect(isValid).toHaveBeenCalled();
});
it('should pass when a string\'s length is bigger', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 'myValue'}});
expect(isValid).toHaveBeenCalled();
});
it('should fail with an empty string', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: ''}});
expect(isValid).not.toHaveBeenCalled();
})
it('should fail with an undefined', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: undefined}});
expect(isValid).not.toHaveBeenCalled();
});
it('should fail with a null', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: null}});
expect(isValid).not.toHaveBeenCalled();
});
it('should fail with a number', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 123}});
expect(isValid).not.toHaveBeenCalled();
});
});
it('should fail with null', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: null}});
expect(isValid).not.toHaveBeenCalled();
});
describe('minLength:0', function() {
it('should fail with a number', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 123}});
expect(isValid).not.toHaveBeenCalled();
});
beforeEach(function() {
form = TestUtils.renderIntoDocument(
<Formsy.Form>
<TestInput name="foo" validations="minLength:0"/>
</Formsy.Form>
);
it('should fail when a string\'s length is smaller', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 'hi'}});
expect(isValid).not.toHaveBeenCalled();
});
input = TestUtils.findRenderedDOMComponentWithTag(form, 'INPUT');
});
it('should pass when a string\'s length is equal', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 'bar'}});
expect(isValid).toHaveBeenCalled();
});
it('should pass when a string\'s length is bigger', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 'myValue'}});
expect(isValid).toHaveBeenCalled();
});
it('should pass with empty string', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: ''}});
expect(isValid).toHaveBeenCalled();
})
it('should fail with undefined', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: undefined}});
expect(isValid).not.toHaveBeenCalled();
});
it('should fail with null', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: null}});
expect(isValid).not.toHaveBeenCalled();
});
it('should fail with a number', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 123}});
expect(isValid).not.toHaveBeenCalled();
});
it('should pass when a string\'s length is bigger', function () {
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: 'myValue'}});
expect(isValid).toHaveBeenCalled();
});
});

View File

@ -1,4 +1,8 @@
module.exports = {
var isExisty = function (value) {
return value !== null && value !== undefined;
};
var validations = {
isDefaultRequiredValue: function (values, value) {
return value === undefined || value === '';
},
@ -6,7 +10,7 @@ module.exports = {
return !!value;
},
matchRegexp: function (values, value, regexp) {
return !!value && !!value.match(regexp);
return isExisty(value) && regexp.test(value);
},
isUndefined: function (values, value) {
return value === undefined;
@ -15,7 +19,7 @@ module.exports = {
return value === '';
},
isEmail: function (values, value) {
return !value || value.match(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i);
return validations.matchRegexp(values, value, /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i);
},
isTrue: function (values, value) {
return value === true;
@ -24,7 +28,7 @@ module.exports = {
return value === false;
},
isNumeric: function (values, value) {
if (!value) {
if (!isExisty(value)) {
return false;
}
if (typeof value === 'number') {
@ -45,10 +49,10 @@ module.exports = {
return value && /^[a-zA-Z\s]+$/.test(value);
},
isSpecialWords: function (values, value) {
return !value || value.match(/^[a-zA-Z\s\u00C0-\u017F]+$/);
return !value || /^[a-zA-Z\s\u00C0-\u017F]+$/.test(value);
},
isLength: function (values, value, length) {
return value && value.length === length;
return isExisty(value) && value.length === length;
},
equals: function (values, value, eql) {
return value == eql;
@ -57,9 +61,11 @@ module.exports = {
return value == values[field];
},
maxLength: function (values, value, length) {
return value && value.length && value.length <= length;
return isExisty(value) && value.length <= length;
},
minLength: function (values, value, length) {
return value && value.length && value.length >= length;
return isExisty(value) && value.length >= length;
}
};
module.exports = validations;