Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isNumeric to support floating points #810

Merged
merged 3 commits into from
May 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/isNumeric.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var _assertString2 = _interopRequireDefault(_assertString);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var numeric = /^[-+]?[0-9]+$/;
var numeric = /^[+-]?([0-9]*[.])?[0-9]+$/;

function isNumeric(str) {
(0, _assertString2.default)(str);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/isNumeric.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assertString from './util/assertString';

const numeric = /^[-+]?[0-9]+$/;
const numeric = /^[+-]?([0-9]*[.])?[0-9]+$/;

export default function isNumeric(str) {
assertString(str);
Expand Down
16 changes: 8 additions & 8 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -1463,9 +1463,9 @@ describe('Validators', function () {
'0',
'-0',
'+123',
'123.123',
],
invalid: [
'123.123',
' ',
'.',
],
Expand Down Expand Up @@ -2960,12 +2960,12 @@ describe('Validators', function () {
'Vml2YW11cyBmZXJtZW50dW0gc2VtcGVyIHBvcnRhLg==',
'U3VzcGVuZGlzc2UgbGVjdHVzIGxlbw==',
'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuMPNS1Ufof9EW/M98FNw' +
'UAKrwflsqVxaxQjBQnHQmiI7Vac40t8x7pIb8gLGV6wL7sBTJiPovJ0V7y7oc0Ye' +
'rhKh0Rm4skP2z/jHwwZICgGzBvA0rH8xlhUiTvcwDCJ0kc+fh35hNt8srZQM4619' +
'FTgB66Xmp4EtVyhpQV+t02g6NzK72oZI0vnAvqhpkxLeLiMCyrI416wHm5Tkukhx' +
'QmcL2a6hNOyu0ixX/x2kSFXApEnVrJ+/IxGyfyw8kf4N2IZpW5nEP847lpfj0SZZ' +
'Fwrd1mnfnDbYohX2zRptLy2ZUn06Qo9pkG5ntvFEPo9bfZeULtjYzIl6K8gJ2uGZ' +
'HQIDAQAB',
'UAKrwflsqVxaxQjBQnHQmiI7Vac40t8x7pIb8gLGV6wL7sBTJiPovJ0V7y7oc0Ye' +
'rhKh0Rm4skP2z/jHwwZICgGzBvA0rH8xlhUiTvcwDCJ0kc+fh35hNt8srZQM4619' +
'FTgB66Xmp4EtVyhpQV+t02g6NzK72oZI0vnAvqhpkxLeLiMCyrI416wHm5Tkukhx' +
'QmcL2a6hNOyu0ixX/x2kSFXApEnVrJ+/IxGyfyw8kf4N2IZpW5nEP847lpfj0SZZ' +
'Fwrd1mnfnDbYohX2zRptLy2ZUn06Qo9pkG5ntvFEPo9bfZeULtjYzIl6K8gJ2uGZ' +
'HQIDAQAB',
],
invalid: [
'12345',
Expand Down Expand Up @@ -4136,7 +4136,7 @@ describe('Validators', function () {
test({
validator: 'isCurrency',
args: [
{ },
{},
'-$##,###.## (en-US, en-CA, en-AU, en-NZ, en-HK)',
],
valid: [
Expand Down
2 changes: 1 addition & 1 deletion validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ function isAlphanumeric(str) {
throw new Error('Invalid locale \'' + locale + '\'');
}

var numeric = /^[-+]?[0-9]+$/;
var numeric = /^[+-]?([0-9]*[.])?[0-9]+$/;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Amir. The regex looks like it should do the trick but unfortunately it's been implemented directly into the built version of validator.js. You'll want to implement it in the isNumeric source file, update the tests, and run the build and commit any changes.

The source file is this one: https://github.com/chriso/validator.js/blob/master/src/lib/isNumeric.js

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pietvanzoen , done


function isNumeric(str) {
assertString(str);
Expand Down
2 changes: 1 addition & 1 deletion validator.min.js

Large diffs are not rendered by default.