From: snowyplover Date: Sun, 17 Jan 2016 09:40:56 +0000 (-0800) Subject: Fix regex for isNumber X-Git-Tag: 2.3.0~18^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2131aa385ea8572e2580d094f467bf1403891122;p=svg.js.git Fix regex for isNumber Description of necessary functionality for a regex that matches Javascript numbers found in Eloquent Javascript, (Ch 9, last exercise). See: http://eloquentjavascript.net/09_regexp.html#h_izldJoT3uv --- diff --git a/src/regex.js b/src/regex.js index 1b26afd..d2e6c78 100644 --- a/src/regex.js +++ b/src/regex.js @@ -34,7 +34,7 @@ SVG.regex = { , isBlank: /^(\s+)?$/ // Test for numeric string -, isNumber: /^-?[\d\.]+$/ +, isNumber: /^[+-]?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i // Test for percent value , isPercent: /^-?[\d\.]+%$/ @@ -64,4 +64,4 @@ SVG.regex = { // matches X , X: /X/g -} \ No newline at end of file +}