Skip to content

Instantly share code, notes, and snippets.

@AnalyzePlatypus
Created June 28, 2023 12:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AnalyzePlatypus/db10ea7f8aef36f5fc9f9ce5e861bb4b to your computer and use it in GitHub Desktop.
Save AnalyzePlatypus/db10ea7f8aef36f5fc9f9ce5e861bb4b to your computer and use it in GitHub Desktop.
Detect Israeli Kosher phone numbers with JavaScript

Detect Israeli Kosher Phone Numbers

Based on a code sample provided to me by Avi Marcus.

// Valid as of 2018-10-19
// https://en.wikipedia.org/wiki/Telephone_numbers_in_Israel#Kosher_numbers

const KOSHER_PHONE_MOBILE_REGEX = /^0(5041|5271|5276|5331|5341|5484|5485|5567|5571|5598|5832)\d{5}$/;
const KOSHER_PHONE_FIXED_REGEX = /^0([23489]80\d{5}|7229\d{5}|73724\d{4})$/;

const NON_DIGITS_REGEX = /\D/g;
const LEADING_AREA_CODE_REGEX = /^(\+|00|011)?972/;

function isIsraeliKosherPhoneNumber(phoneNumber){ 
  if (typeof phoneNumber !=='string') phoneNumber = '' + phoneNumber; // Coerce number to String, if it isn't already
  phoneNumber = phoneNumber.
    replace(NON_DIGITS_REGEX, ''). 
    replace(LEADING_AREA_CODE_REGEX,'0');
  return KOSHER_PHONE_MOBILE_REGEX.test(phoneNumber) || KOSHER_PHONE_FIXED_REGEX.test(phoneNumber);
}

// Usage

isIsraeliKosherPhoneNumber('0501111111');
// => false
isIsraeliKosherPhoneNumber('0583241111')
// => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment