RosettaCodeData/Task/Determine-if-a-string-is-numeric/Emacs-Lisp/determine-if-a-string-is-numeric-1.el
2026-04-30 12:34:36 -04:00

12 lines
579 B
EmacsLisp

(defun string-valid-number-p (str)
"Test if STR is a numeric string.
Eliminate strings with commas in them because ELisp numbers do
not contain commas. Then check if remaining strings would be
valid ELisp numbers if the quotation marks were removed."
(and
;; no comma in string, because ELisp numbers do not have commas
;; we need to eliminate any string with a comma, because the
;; numberp function below will not weed out commas
(not (string-match-p "," str))
;; no errors from numberp function testing if a number
(ignore-errors (numberp (read str)))))