EAN/ISBN Validation and Calculation in 140byte.es JavaScript

Validate EAN-13 and ISBN-13 Numbers.

The tiny JavaScript function isValidEan13() (82 bytes currently) returns true if a given EAN-13 (International Article Number) or ISBN-13 (International Standard Book Number) is valid. formatEan13() (118 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.

Created by Thiemo Mättig in January 2012 for 140byte.es. Thanks to @tsaniel for saving a lot of bytes.

Show the source of this page or visit the Gist at GitHub.