Actually check for invalid floats

This commit is contained in:
Hana Wang 2015-02-26 04:59:19 -08:00
parent a65b2943b0
commit 9ef8590f80
2 changed files with 34 additions and 1 deletions

View File

@ -162,4 +162,32 @@ describe('Validation', function() {
});
it('RULE: isNumeric is false (string representation of an invalid float)', function () {
var isValid = jasmine.createSpy('valid');
var 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}/>
}
});
var form = TestUtils.renderIntoDocument(
<Formsy.Form>
<TestInput name="foo" value="foo" validations="isNumeric"/>
</Formsy.Form>
);
var input = TestUtils.findRenderedDOMComponentWithTag(form, 'INPUT');
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: '1.'}});
expect(isValid).not.toHaveBeenCalled();
});
});

View File

@ -14,7 +14,12 @@ var validationRules = {
if (typeof value === 'number') {
return true;
} else {
return value.match(/[-+]?(\d*[.])?\d+/);
matchResults = value.match(/[-+]?(\d*[.])?\d+/);
if (!! matchResults) {
return matchResults[0] == value;
} else {
return false;
}
}
},
'isAlpha': function (value) {