Number Text Editor

Hi, 

Juce needs a number text edit, seriously! I am stunned how this feature was missed in all the updates.

Cheers

TextEditor::setInputRestrictions()

Rail

As a quick/dirty example... textEditor called 'txtNumbers',  use setInputRestrictions(length, characters)

    // p0: length -> in example, max 10 characters
    // p1: valid characters -> in example, numerics only
    txtNumbers->setInputRestrictions(10, "0123456789");

 

Quick and dirty indeed. ;) 

You want to allow negative / positive numbers and floating point numbers so you have to allow "0123456789+-,." And at this point, you have to parse the string. And even then, a good input field would only allow inputs, that are valid, signs (+/-) only as the first characters etc.

1 Like

Then use TextEditor::setInputFilter and write whatever kind of fancy restrictions you want.

Seems like you're being critical of the class before actually looking at what it has to offer.

1 Like

Hi,

Is it possible to use regular expressions as inputs to setInputRestrictions()?
I’m trying to forbid any input characters different from numbers, spaces and english letters.
This is how I’m doing it now:
m_txtNameEditor->setInputRestrictions(kAppMaxIMUNameLenght - 1, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ");

Is there a simpler way?

Thanks,
Amitai

It’s probably simple enough to create your own function which can generate the String you’d like rather than using a literal… there are no built in methods to do that.

Rail

Sure I can add a function for that purpose, but I expected to find a built in service for that. Thanks anyway :slight_smile: