There is not exactly a single formula, but about seven or eight ranges of area numbers (first 3 digits) that are not used. Also, about two dozen SSN's that have been used in advertising, making them invalid.
The best website for ranges, tables, and the various rules used to validate SSN's, is:
If you need to be even more precise and determine if an SSN is potentially valid, but not yet used (and therefore not yet valid), the SSA puts out tables at their website that show the highest ranges of area (1st 3), group (2nd 2), and serial (last 4) numbers that are issued each month.
In short, the easy way is to incorporate the seven or eight ranges of invalid area numbers into your filter - - the most accurate way is to use Monarch's HTML capability and read the SSA's tables every month.