UNPKG

@valkyriestudios/validator

Version:

A lightweight configurable javascript validator

22 lines (21 loc) 694 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.vPhone = vPhone; exports.default = vPhone; const RGX = /^\+?\d{0,4}[-.\s]?\(?\d{1,3}\)?[-.\s]?\d{1,4}[-.\s]?\d{1,4}[-.\s]?\d{1,9}$/; function vPhone(val) { if (typeof val !== 'string') return false; if ((val.match(/\d/g) || []).length < 5) return false; const sparts = val.replace(/(\.|-)/g, ' ').split(' '); for (const el of sparts) { const first = el[0]; const last = el[el.length - 1]; if (first === '(' && last !== ')') return false; if (last === ')' && first !== '(') return false; } return RGX.test(val); }