Skip to content

Instantly share code, notes, and snippets.

View emilbillberg's full-sized avatar

Emil Billberg emilbillberg

View GitHub Profile
@emilbillberg
emilbillberg / validator.js
Created July 14, 2016 13:21
Common Swedish validation in Javascript
/***************** POSTAL CODE *****************/
// cannot start with a zero and must contain 5 digits.
let postalCode = "12345";
let regexPostalCode = new RegExp("^[1-9][0-9]{4}$");
let postalCodeMathces = postalcode.match(regexPostalCode);
console.log('POSTAL CODE MATCHES:', postalCodeMathces !== null);
/***************** PERSONAL NUMBER *****************/
// can only start with one or two
// second character can only be a nine or zero