UNPKG

s-valid

Version:
21 lines (20 loc) 551 B
"use strict"; exports.__esModule = true; // ----- zip code // -- 1. input must be a string // -- 2. check number // -- 3. perform regex test // --------------------------------------- function default_1(s) { // [1] throws here if not a string s = s.toLowerCase(); // [2] every zip code begins with a number, and none are < 00501 var numeric = parseInt(s, 10); if (isNaN(numeric) || numeric < 501) return false; // [3] var regex = /^\d{5}(-\d{4})?$/; return regex.test(s); } exports["default"] = default_1; ;