1 страниц (7 вхождений)
Validating Input String - Сообщения
#1 Опубликовано: 06.12.2023 01:30:03
What would be the best way to validate an input string in order to ensure it is a number and does not include any other characters?
Keep in mind that I'm referring to actual input in string form that is then converted into a number via str2num().
Keep in mind that I'm referring to actual input in string form that is then converted into a number via str2num().
#2 Опубликовано: 06.12.2023 12:56:39
#3 Опубликовано: 06.12.2023 18:12:00
Here is a less compact solution, can be adapted to accept different characters.
(Positive/negative values can be allowed with an additional condition on the first character)
![2023-12-06 10_45_05-SMath Solver - [test_input.sm].png](/ru-RU/file/3AS5dy/2023-12-06-10_45_05-SMath-Solver---_test_input_sm__png)
test_input.sm (12 КиБ) скачан 23 раз(а).
(Positive/negative values can be allowed with an additional condition on the first character)
test_input.sm (12 КиБ) скачан 23 раз(а).
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
2 пользователям понравился этот пост
#4 Опубликовано: 06.12.2023 21:54:14
Signed numbers allowed. Also, compared with str2num results.
check.sm (12 КиБ) скачан 24 раз(а).

Best regards.
Alvaro.
check.sm (12 КиБ) скачан 24 раз(а).
Best regards.
Alvaro.
2 пользователям понравился этот пост
#5 Опубликовано: 07.12.2023 03:16:07
Near identical to Davide, this is how I would do it.
At least this is what I have done in QBasic long ago.
Regards
IsNumber.sm (7 КиБ) скачан 24 раз(а).

At least this is what I have done in QBasic long ago.
Regards
IsNumber.sm (7 КиБ) скачан 24 раз(а).
4 пользователям понравился этот пост
NDTM Amarasekera 08.12.2023 09:50:00, sergio 07.12.2023 16:48:00, Oscar Campo 07.12.2023 17:26:00, Wesly Centerwall 08.12.2023 05:53:00
#6 Опубликовано: 08.12.2023 05:52:28
Thanks guys for the input. All very insightful and useful!
1 страниц (7 вхождений)
-
Новые сообщения
-
Нет новых сообщений