MCPcopy Create free account
hub / github.com/Superflows-AI/superflows / isPhoneNumber

Function isPhoneNumber

lib/utils.ts:460–479  ·  view source on GitHub ↗
(string: string)

Source from the content-addressed store, hash-verified

458}
459
460export function isPhoneNumber(string: string): boolean {
461 // Below regex checks for the format of a phone number. It's a little loose since it
462 // has to allow country codes and different formatting of spaces, hyphens and brackets.
463 // We have further sanity checks below (no letters, right number of numbers)
464 const phoneNumRegex =
465 /^(\+?\d{1,3}[-.\s]?)?\(?\d{1,3}\)?[-.\s]?(\d{1,2})?[-.\s]?(\d{3,4})?[-.\s]?(\d{3,9})$/;
466
467 const broadlyRightFormat = phoneNumRegex.test(string);
468 if (!broadlyRightFormat) return false;
469
470 // Check if right number of numbers
471 const numberCount = string.replace(/\D/g, "").length;
472 // Reason for 10-13 range is phone numbers have 11 numbers, but there's an optional 0
473 // at the front and country code can add 3 (e.g. +44) which replaces the 0
474 // (strictly speaking, a country code can add >3, but these countries are rare)
475 const numberCountCorrect = 10 <= numberCount && numberCount <= 13;
476 if (!numberCountCorrect) return false;
477 // Check if there are any letters
478 return !/[a-z]/i.test(string);
479}
480
481export function isName(string: string): boolean {
482 // Check for strings with no numbers, optionally capitalised first letters

Callers 3

isTextWithSubstanceFunction · 0.90
isID.test.tsFile · 0.90
isIDFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected