Validate ListBox Numeric Values

I’m new to Xojo; have a ListBox question.
I’ve populated a ListBox with data from my SQLite database - storing (let’s say) myMonth in Column 0 and myAmount in Column 1.

On the initial ListBox load (and subsequent updates),
–> I’ve placed the display value in Cell(row,col) and the raw value in CellRow(row,col)
–> In the CellTextPaint Handler I format column 1 (myAmount) using a currency format including a “$”, etc.

When the user selects the Col 1 cell to be edited, I would like to:
–> Replace the cell content with just the number (e.g. $123,456.34 becomes 123456.23)
–> Validate the entry when they leave the cell
–> On validation, if the entry is not numeric, return the cell value to its previous value
–> On validation, if the entry is numeric, store the raw number in CellTag and format the Cell value with “$”, etc.

A nudge in the right direction would be much appreciated … I’ve searched the examples and cannot find any cell validation routines

If isNumeric(replaceall(replaceall(s,"$",""),".","") then 

assuming “s” is your text value
but BECAREFUL… the US uses “.” [period] for decimal points and “,” [comma] for thousands
but Europe is the exact opposite in some cases

I’m sure Kem will come along shortly and give a RegEx that will work even better :slight_smile:

Thank you - that is helpful on the numeric validation part.
Still struggling with the sequencing of the Listbox and how to interrupt it.

– Assume the ListBox is populated
– User clicks in a cell and changes the cell value … then hits tab, clicks on a cell, etc.
– At that point, I want to “validate” the cell value (I have a method for that and can call it in CellAction)
— If Valid: continue on to the cell the user entered (I have that figured out - Just let CellAction do its thing)
— If Not Valid: I want it to stay on the cell just updated, revert back to the old value and give a MSGBOX message

Can’t seem to determine how to interrupt the user’s new cell selection and force them back into edit mode on the cell they just tried to leave.

and in the very unlucky case you have some adventurous user who has set them to something custom and they are multiple characters (yes this is possible)

dont rely on them being ONLY , and . - they could be ANYTHING (including spaces)

something like this will get you the right strings the person has used

dim thousands as string = replaceall( format( 1111, “0,000”), “1”, “” )
dim decimal as string = replaceall( format( 1.1, “0,0”), “1”, “” )

shouldn’t your 2nd example be

dim decimal as string = replaceall( format( 1.1, "0.0"), "1", "" )

I wrote that in the forums so it may well need to be that :stuck_out_tongue: