Validate Swedish Personal Identity Number (personnummer) using JavaScript

Put together a function to validate Swedish Personal Identity Numbers (personnummer) using JavaScript for use in client-side form input validation.