V
V
Vlad2021-05-21 10:40:23
JavaScript
Vlad, 2021-05-21 10:40:23

How to do prompt validation?

How to check for an empty string (a space is also an empty string), for cancellation, for a number and for the number 0.
I can’t find the necessary information, or I’m not asking the right question.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2021-05-21
@Alexandre888

let string = prompt(". . .", "")

// проверка на пустую строку (пробел - тоже пустая строка)
if (string.length === 0 || string === " ") . . .

// проверка на отмену (prompt() возвращает null, если была произведена отмена)
if (string === null) . . .

Further, you can do it yourself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question