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.
Should the function return false if there are more than 13 digits?