# Filtering text out of number fields

**URL:** <https://forum.servoy.com/t/filtering-text-out-of-number-fields/2754>\
**Category:** Classic Servoy\
**Created:** [September 23, 2004, 2:25am UTC](https://forum.servoy.com/t/filtering-text-out-of-number-fields/2754 "2004-09-23T02:25:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Morley](https://avatars.discourse-cdn.com/v4/letter/m/7cd45c/32.png) [@Morley](https://forum.servoy.com/u/Morley)\
**Post date:** [September 23, 2004, 2:25am UTC](https://forum.servoy.com/t/filtering-text-out-of-number-fields/2754/1 "2004-09-23T02:25:06Z")

</div>

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

```auto
utils.stringToNumber(field_name);

```

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

---

<div class="post-metadata">

**Author:** ![Harry\_Catharell](https://avatars.discourse-cdn.com/v4/letter/h/e19adc/32.png) [@Harry\_Catharell](https://forum.servoy.com/u/Harry_Catharell)\
**Post date:** [September 23, 2004, 8:33am UTC](https://forum.servoy.com/t/filtering-text-out-of-number-fields/2754/2 "2004-09-23T08:33:00Z")

</div>

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 :

```auto
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

---

<div class="post-metadata">

**Author:** ![Morley](https://avatars.discourse-cdn.com/v4/letter/m/7cd45c/32.png) [@Morley](https://forum.servoy.com/u/Morley)\
**Post date:** [September 23, 2004, 1:09pm UTC](https://forum.servoy.com/t/filtering-text-out-of-number-fields/2754/3 "2004-09-23T13:09:01Z")

</div>

Hi Harry

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