How to Validate CAS Registry Numbers in JavaScript

October 20th, 2011

Some time ago I needed to validate CAS Numbers in Ruby. Recently, I needed to validate CAS Numbers in JavaScript. The problem boils down to comparing the terminal check digit with the expected value. The function validateCAS does the trick:

To test, open up a browser or Node.js console, include the above function, and use:

> console.log(validateCAS('107-07-3')); // prints true