The tiny JavaScript function isValidEan13()
(82 bytes currently) returns true if a given [EAN-13](http://en.wikipedia.org/wiki/International_Article_Number_(EAN\)) (International Article Number) or ISBN-13 (International Standard Book Number) is valid. formatEan13()
(126 bytes) calculates and appends the checksum (or replaces wrong checksums) and formats the number with spaces.
Both functions accept strings and numbers.
The core of the later function is the call split(/\D*/)
. The regular expression matches every sequence of non-digits including empty sequences. This splits the input into individual digits and removes all non-digits the same time.
I must admit, I'm shocked. I expected somebody could save one or two bytes, but golfing 11% away from a 83 bytes function is impressive.
I would like to add the length check, as suggested. Here is what I got so far (84 bytes), based on your version.