Skip to content

Instantly share code, notes, and snippets.

@karna41317
Created October 9, 2016 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karna41317/d3ce512be287102bd56bcb11f05b8b01 to your computer and use it in GitHub Desktop.
Save karna41317/d3ce512be287102bd56bcb11f05b8b01 to your computer and use it in GitHub Desktop.
export function isValidPersonalNumber (personalNumber) {
let matches = personalNumber
.match(/^(19|20)((\d{2})(\d{2})(\d{2})-{0,1}\d{4})$/);
if (matches) {
let year = parseInt(matches[1] + matches[3], 10);
return !!(year < CURRENT_YEAR && isValidSwedishPIN(matches[2]));
} else {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment