Filtering text out of number fields

I’d like to prevent users entering anything but numbers in a field. Therefore I’m using this function in a focusLost method:

utils.stringToNumber(field_name);

Doesn’t work. I’m obviously missing something.

Hi Morley,

You are nearly there !

You are telling it what to do but not where to put the result !

Change the method to read :

field_name = utils.stringToNumber(field_name);

You may also have to format the number returned to get rid of decimal places using ‘toFixed()’ !!

Is the field a text or a numeric field ?

Harry

Hi Harry

Of course! I wasn’t thinking. Thanks, and for the decimal aspect as well.