PDA

View Full Version : input filtering



sandyrepope
23-02-2007, 01:22
In my console program I'm writing I need a way to get a number from the user. It needs to accept only digits (numbers from 0-100). Right now I'm using console_readline and I need a way to keep the user from typing in letters.

Is there something built in to thinbasic that will do this or do I need to write a function?

Thanks

ErosOlmi
23-02-2007, 01:29
Right now you need to write your own functions but your request in nice.
Give me few days (I've something urgent to finish for the next two days) and I will add one or two native functions for reading numbers.

:D

kryton9
23-02-2007, 01:40
Wow, input function with validation for specific entries would be neat. They could even be just separate commands to make it easy to make and use.

input:
only numbers: 0 1 2 3 4 5 6 7 8 9
only numbers and separators: 0 1 2 3 4 5 6 7 8 9 , .
money: $ 0 1 2 3 4 5 6 7 8 9 , . the dollar sign could be also for Euro and other currency symbols
input only phone numbers (012) 345-6789

Well you get the idea. Good recommendation Sandy, Eros will make something awesome when he has the time you can count on that!!

ErosOlmi
23-02-2007, 01:46
To start, you can already use VERIFY (http://www.thinbasic.com/public/products/thinBasic/help/html/verify.htm) function to test if input string contains only the chars you want.

VERIFY returns zero if each character in MainString is present in MatchString. If not, it returns the position of the first non-matching character in MainString.



DIM lPos AS LONG
'---returns 4 since "." is not in "0123456789"
lPos = VERIFY("123.65,22.5", "0123456789")

kryton9
23-02-2007, 02:24
Wow, that is perfect then. Very flexible way to handle it!!