Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Smalltalk: how to check wether a string contains only numbers?

so basically I have some input possibilities for the user where should only numbers be accepted, otherwise the user will be alerted his input was incorrect.

the input is considered a String when I read it out using a callback. now I want to check whether the string(which SHOULD contain numbers) actually DOES ONLY contain numbers, but I didnt find a solution implemented already. i tried

theString isInteger 

-is never true for the string

theString asNumber 

- ignores letters, but I want to have a clear output wether letters are included in the string or not

theString isNumber

- always false

like image 252
roqstr Avatar asked Dec 05 '22 05:12

roqstr


1 Answers

In Squeak and Pharo, you have the message #isAllDigits that does exactly what you want:

'1233248539487523' isAllDigits "--> true"
like image 111
Tobias Avatar answered Mar 16 '23 09:03

Tobias