Page 1 of 1

Editbox for numbers only

Posted: Wed Aug 09, 2006 17:04
by mustill
Hi guys!

This is my firts project with CEGUI and I've got a problem which seems to be very simple, but for me it's impossible to solve it. All I need to do is an editbox for numbers only.

I tried 2 ways. First was of course Spinner, but the problem was that I could change the number only by the arrows (not by writing it in the box). I got similar result with the second way - ValidationString and RegEx. This time it was impossible to change the text at all.

I also tried to find any topic which covered this problem but I found none.

So if you could please give me at least some hint...

Thanks in advance
Must Ill

Posted: Wed Aug 09, 2006 21:35
by Van
I think you want to use a CEGUI::Editbox and the CEGUI::Editbox::setValidationString(). Also, look at the Events that can information of validation states.

Posted: Thu Aug 10, 2006 06:04
by mustill
Thanks Van, but I already know that (as I wrote above), but the problem is that when I set the validation string the user cannot write in the editbox.

Here's what I used as validation string:
"[3-5][0-9]{4}"
As far as I know RegExes this should allow the user to enter numbers between 30000 and 59999 (and that's what I need :)). I think that probably the problem is that the validation string must stand all the time, so if the editbox is empty at the beginning it would oppose the val. string each time a key is pressed.
"/d*"
I hope ( :D ) this should mean "string made only of digits with any length". If at least this could work I would be able to check whether the number is in the range I want it to be by myself later (for example when the "Start Game" button is pressed). But the problem with not beaing able to write in remains.
".*"
Well, this is the only RegEx I got to work, but for me it's useless :twisted:

Please, if you've got experience with this give me a hint...

Thanks in advance
Must Ill

Posted: Thu Aug 10, 2006 12:24
by Rackle
Have a look at the code within [http://www.cegui.org.uk/wiki/index.php/Formatted_Numeric_Data]Formatted_Numeric_Data[/url], more precisely the spinner control's onSpinnerValueChanged() within the FormattedData class. I'm basically converting a numeric value into a different display string; the internal value of the object is "validated" and then a formatted string is being displayed.

Using this approach you could validate the value of the editbox yourself and if valid then display that value/digit otherwise remove that digit.