I need to validate input to make sure it's a valid Hebrew year number, which can only have certain valid sequences of letters.
Something like (pseudo regex) ([:thousands:]')?[:hundreds combinations:][:tens:]?("[:alef-tes digits:])?
But then sometimes it's only single digits, or tens etc without any hundreds or thousands...
Not sure what it's formally called, the Hebrew Numeric system? Hebrew Numerology? Hebrew Numeral System? Gematria? Overview described here: https://en.wikipedia.org/wiki/Hebrew_numerals Test here: https://hebrewnumerals.github.io/ Examples:
- 1 = א
- 15 = ט"ו
- 16 = ט"ז
- 42 = מ"ב
- 133 = קל"ג
- 499 = תצ"ט
- 501 = תק"א
- 651 = תרנ"א
- 765 = תשס"ה
- 872 = תתע"ב
- 1015 = א׳ט"ו
- 1724 = א׳תשכ"ד
- 2389 = ב׳שפ"ט
- 4129 = ד׳קכ"ט
- 4487 = ד׳תפ"ז
- 6298 = ו׳רצ"ח
- 7892 = ז׳תתצ"ב
- 9301 = ט׳ש"א
Some examples of invalid year numbers:
- ז׳צת"ב (Taf 400 cannot be after Tzadik 90)
- שר"ו (Shin 300 followed by Resh 200 invalid, should have been Taf 400 followed by Kuf 100)
- פ'א"ב (Alef 1 followed by Bet 2 not ok, should be Gimmel 3)
- ל"מ bad - should've been ע
- ט"ט bad - should've been י"ח
(Tried searching for existing libraries or calendar source codes, gave regex101 a bunch of tries)
PHP non-regex workaround I'm using for now:
numberToHeb($num)that reliably converts a number (ex 4345) into a properly formulated hebrew number (ד'שמ"ה). Currently making use of built in PHP calendar conversion functions taking advantage of the year number as a general purpose convert-number-to-hebrew functionality (limited to 1-9999 range)hebNumber($str)to take any hebrew number (ex ד'שמ"ה) wishing to be validated if it is a valid formulation of any hebrew number (1-9999 in this case). In this function;numberToHeb($num)function from step #1, check if the resulting string matches the string given to thehebNumber($str)function, If matches = passes validation, otherwise it was not a properly formed hebrew number.