Regular expression /\d/ matches "digits" other than [0-9]

"Igor Tandetnik" <[email protected]> Tue, 24 Apr 2007 19:24:36 -0400
Newsgroups gmane.comp.mozilla.internationalization
Message-ID <[email protected]>
/\d/.test("\uFF11")

returns true. U+FF11 is FULLWIDTH DIGIT ONE, and happens to have Unicode 
class Nd (decimal number). However, Ecma-262 (the standard for 
EcmaScript aka JavaScript) explicitly states:

15.10.2.12 CharacterClassEscape
The production CharacterClassEscape :: d evaluates by returning the 
ten-element set of characters containing the characters 0 through 9 
inclusive.

So accepting "digits" other than [0-9] appears to be a bug. Am I missing 
something obvious?


I wouldn't mind this behavior, if things like parseInt would also 
understand the same set of digits. I submit it should be the case that, 
modulo overflow, for every (short enough) string s, if /^\d+$/.test(s) 
returns true then parseInt(s, 10) should return a number other than NaN.

Yes, I realize that I can replace \d with [0-9] and \D with [^0-9]. This 
makes even moderately complicated regular expressions considerably 
harder to read though.

Igor Tandetnik