From f51768471137a37181a5acb3eb92ddd6c3e91a14 Mon Sep 17 00:00:00 2001 From: GCorbel Date: Sat, 19 Nov 2016 07:21:42 -0500 Subject: [PATCH] Allow to use coma in numbers --- addon/number.js | 4 ++++ tests/unit/validators/number-test.js | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/addon/number.js b/addon/number.js index d7a28cd..dc4a54a 100755 --- a/addon/number.js +++ b/addon/number.js @@ -36,6 +36,10 @@ const { * @param {String} attribute */ export default function validateNumber(value, options) { + if (typeof value === 'string') { + value = value.replace(/,/g, '.'); + } + let numValue = Number(value); let optionKeys = Object.keys(options); let { allowBlank, allowString, integer } = getProperties(options, ['allowBlank', 'allowString', 'integer']); diff --git a/tests/unit/validators/number-test.js b/tests/unit/validators/number-test.js index d01ec13..23c170a 100644 --- a/tests/unit/validators/number-test.js +++ b/tests/unit/validators/number-test.js @@ -23,7 +23,7 @@ test('no options', function(assert) { }); test('allow string', function(assert) { - assert.expect(6); + assert.expect(7); options = { allowString: true @@ -35,6 +35,9 @@ test('allow string', function(assert) { result = validate('22.22', cloneOptions(options)); assert.equal(processResult(result), true); + result = validate('22,22', cloneOptions(options)); + assert.equal(processResult(result), true); + result = validate('test', cloneOptions(options)); assert.equal(processResult(result), 'This field must be a number');