Page 1 of 1

Editbox -> Just no.?!

Posted: Wed Jan 28, 2009 14:17
by fame
Hi,

how can i get the editbox to only accept no. like "23.1282"?

Is that the validation string? I didnt get that worked, could you help me?

Thanks! :)

Regards,
fame

Posted: Wed Jan 28, 2009 14:56
by CrazyEddie
Hi,

You are correct that the validation string can be used to limit acceptable input to the editbox. The validation string is a regular expression that the editbox text string must match in order to be 'valid', and any input that would cause the string to become invalid is rejected.

This throws up key point, that the regular expression must match at all times, sometimes this means a slightly more complex regex than might otherwise have been needed.

Anyway, to limit the text to digits, with an optional decimal point - which must be preceded by at least one digit (i.e. a useful number limiting regex) would look something like this:

Code: Select all

"\d*?(\d+\.)?\d*"


Dont forget that if you put that in a C++ string literal, you have to escape the backslashes, so:

Code: Select all

"\\d*?(\\d+\\.)?\\d*"


HTH

CE.

Posted: Wed Jan 28, 2009 15:57
by fame
Thanks a lot!

The problem was i chosed the wrong regexp. Thats definitly a thing i should learn!