Asterisk pattern matching
Simple package with no dependecies for validation phone numbers according to given asterisk pattern.
Install with
npm install asterisk-pattern-matching
Usage Example
// function to verify the asterisk pattern truthconst validateNumber = // list of examples, return true or false // true // true // false // true // true // true // true // true // true // false // true
// function to verify the asterisk pattern truth and parse number by given settingsconst parseNumber = // list of examples, function ends at first pattern matchconst myPatterns = /* { pattern:, // (String) asterisk pattern deleteFromStart:, // (String|Number) indicates, how many chars should be removed from number's START deleteFromEnd:, // (String|Number)indicates, how many chars should be removed from number's END prefix:, // (String|Number) indicates, what should be added to number's START suffix: // (String|Number) indicates, what should be added to number's END }, */ pattern: '_77X.' deleteFromStart: 1 deleteFromEnd: 1 prefix: '***' suffix: '###' pattern: '_[*#0-9].' deleteFromStart: '2' deleteFromEnd: '1' prefix: 123 suffix: 321 pattern: '_+X.' deleteFromStart: 4 deleteFromEnd: 3 prefix: '0' suffix: '123' // [] = removed, () = added// second pattern (_[*#0-9].) from variable myPatterns is valid, // (123)[+4]20999888-7[7](321) => result 12320999888-7321// function stops after first valid pattern // last pattern (_+X) from variable myPatterns is valid, // (9)[+420]999888[-77](123) => result 0999888123