Editbox for numbers only

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

mustill
Just popping in
Just popping in
Posts: 3
Joined: Tue Aug 08, 2006 10:11
Contact:

Editbox for numbers only

Postby mustill » Wed Aug 09, 2006 17:04

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

User avatar
Van
Just can't stay away
Just can't stay away
Posts: 225
Joined: Fri Jan 21, 2005 20:29
Contact:

Postby Van » Wed Aug 09, 2006 21:35

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.

mustill
Just popping in
Just popping in
Posts: 3
Joined: Tue Aug 08, 2006 10:11
Contact:

Postby mustill » Thu Aug 10, 2006 06:04

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

Rackle
CEGUI Team (Retired)
Posts: 534
Joined: Mon Jan 16, 2006 11:59
Location: Montréal

Postby Rackle » Thu Aug 10, 2006 12:24

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.


Return to “Help”

Who is online

Users browsing this forum: No registered users and 9 guests