]> source.dussan.org Git - svg.js.git/commitdiff
Fix regex for isNumber 444/head
authorsnowyplover <the.estuary@gmail.com>
Sun, 17 Jan 2016 09:40:56 +0000 (01:40 -0800)
committersnowyplover <the.estuary@gmail.com>
Sun, 17 Jan 2016 09:40:56 +0000 (01:40 -0800)
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

src/regex.js

index 1b26afdc41fa9116b043e97274999c5bed03a594..d2e6c78e8c687e7b9a2434440e5e25c4a14a6df8 100644 (file)
@@ -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
+}