numeric data validation

Hello ,

Another question for you all. I have numeric fields on a form.

If we type in alpha then numeric value (" BX124.5") , it will turn the field red and not accept the data,

however, if i type in numeric then alpha ("124.5BX33), it will accept the entry, just omitting number after the alpa value.

For our solution, we definitely need to not allow ANY alpha entry into numeric fields. An error message pop up would be best. Is there a way for that in servoy?

thanks,
sammy

Yes, the free tool plugin of IT2BE has a function: (out of my head) plugins.it2be_tools.isInteger or isNumber.

You can attach that on the onDataChangem or onLeave property.

sammyzheng:
For our solution, we definitely need to not allow ANY alpha entry into numeric fields. An error message pop up would be best. Is there a way for that in servoy?

At the moment, I don’t know of any way to do this. The issue is that you can’t simply trap and test for a valid number (which you can with [1] Number(fieldValue) and [2] isNaN(fieldValue) in addition to Marcel’s plugin) because number fields absolutely don’t allow alpha characters to be entered first in the field.

So if you enter " BX124.5" in a numeric field, the value goes nowhere. Hence, you can’t test for it in any method. Even if you turn off auto-save on the form.

This is a good question and one which I wish had a better solution.

Thanks for your help guys. I’ll poke around and see if we can find a workaround. Maybe the servoy guys are listening and can offer up something in their later releases.

Why don’t you evaluate the input ondatachange.

You can:

  1. add a global to the field
  2. onrecordselect add data from table/column to the field
  3. on datachange capture the data
  4. evaluate data and throw possible error
  5. change table/column to new value when validated

Hope this helps a little

IT2BE:
Why don’t you evaluate the input ondatachange.

You can:

  1. add a global to the field
  2. onrecordselect add data from table/column to the field
  3. on datachange capture the data
  4. evaluate data and throw possible error
  5. change table/column to new value when validated

Hope this helps a little

Doesn’t work. If alpha characters are entered first into a numeric field, that field literally doesn’t have that data in it. Whether global numeric or table numeric, the last valid value that was in that field is what is actually there even though your new value is displayed in red on the form.

Marcel didn’t say it has to be a numeric global. Make it text and do your tests…

Ah yes, I stand corrected. That definitely works for what it is. However, I would love to see a better solution that can be applied directly to numeric fields without having to go through a global every time…

HJK:
Yes, the free tool plugin of IT2BE has a function: (out of my head) plugins.it2be_tools.isInteger or isNumber.

You can attach that on the onDataChangem or onLeave property.

IT2BE : i’m stumped. i did “application.output(plugins.it2be_tools.isNumber(‘1.5’));” ; it returned “false”

shouldn’t 1.5 return “true”?

No :) why should it… It is a self thinking plugin :lol:

The real anwer is yes, unless, maybe you are working with a comma as decimal delimiter? In that case ‘1.5’ is not a number.

IT2BE:
No :) why should it… It is a self thinking plugin :lol:

The real anwer is yes, unless, maybe you are working with a comma as decimal delimiter? In that case ‘1.5’ is not a number.

:D . How quickly I forget that us americans use “.” as decimal separaters while europe uses “,” . silly me

No not silly. Maybe I can come up with a change to the samples.

I am on the European system but the bulk, I guess, will use the point as decimal seperator.

BTW there IS a system to work without globals. I have placed somewhere on this forum or on Servoy Magazine (can’t remember where) a tip how to work with fields without a dataprovider and still being able to grab the input data. I think however that you can’t use it with an ondatachange event but need to work with onfocuslost instead.