Number Text Editor


#1

Hi, 

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

Cheers


#2

TextEditor::setInputRestrictions()

Rail


#3

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");

 


#4

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.


#5

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.


#6

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


#7

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


#8

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