Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/ui / dist / forms / deps / isValidTelephone.js
Size: Mime:
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});

const tslib_1 = require("tslib");

const exotic_1 = require("exotic");

const isValidLength_1 = tslib_1.__importDefault(require("./isValidLength"));

const matchPhone = /^(?=.*?[1-9])[0-9 ()-.+]+$/;
const matchAlphabets = /^[a-zA-Z]*$/; // {9,9}

const matchPhoneLoose = /^[1-9][0-9-().\s]$/;
const matchSpaceDashSpace = /[\(\)\-\.\+\s]+/gm;
const matchPhoneLoosest = /^(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?$/; // eppPhone match extensible provisioning protocol format
// const eppPhone = /^\+[0-9]{1,3}\.[0-9]{4,14}(?:x.+)?$/
// nanpPhone match north american number plan format
// const nanpPhone = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/

function sanitizeTelephone(value) {
  return exotic_1.isString(value) ? value.replace(matchSpaceDashSpace, '') : value;
}

exports.sanitizeTelephone = sanitizeTelephone;
/**
 * @see https://en.wikipedia.org/wiki/Telephone_numbers_in_the_Solomon_Islands
 * @see https://stackoverflow.com/questions/14894899/what-is-the-minimum-length-of-a-valid-international-phone-number
 * @see https://en.wikipedia.org/wiki/Telephone_numbering_plan
 *
 * 5-15 digits
 *
 * @see isValidLength
 * @param {Number | String} value
 * @return {Boolean}
 */

function isTelephone(value) {
  if (exotic_1.isString(value)) {
    const strippedValue = sanitizeTelephone(value); // 5-15

    if (isValidLength_1.default(strippedValue, 4, 16)) {
      return matchPhone.test(strippedValue) || matchPhoneLoose.test(strippedValue);
    } else {
      return false;
    }
  } else {
    return false;
  }
}

exports.isValidTelephone = isTelephone;
exports.isTelephone = isTelephone;

function isEmptyOrValidTelephone(value) {
  if (exotic_1.isEmpty(value)) {
    return true;
  } else {
    return isTelephone(value);
  }
}

exports.isEmptyOrValidTelephone = isEmptyOrValidTelephone;
exports.default = isTelephone; //# sourceMappingURL=isValidTelephone.js.map