Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 2346 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

I found a thread regarding this from 11 years ago, but couldn't find anything else so thought it may be best to check if the newer versions of FM have a solution to this problem. Is there any function or custom function that would allow me to check if the value in a field is numeric? I have a field that is supposed to be only numeric (primarily only positive integers) however occasionally there are entries like '1 + 4' or '10 + 2'. I'd like to enter the contents of this field into another field, but only with the entries that are numeric only. Any thoughts? Really appreciate any help.

Posted (edited)

Hi Eli

I know someone will have a better answer than this, but my thoughts would be 

1) Make the field type be 'number' and use the fields options validation set to 'Strict Data Type = Numeric'

2) If the field has to be a text field, but you want to check that it is numeric, the you could do something like :-
 

FieldIsNumber = If ( Filter ( numberField ; "0123456789" ) = numberField ; 1 ; 0 )

This Boolean result would be 1 if the field only contained numerals. It would give a positive result for '01234', but this may be OK.

Edited by rwoods
  • Like 1
Posted (edited)

I'm assuming the field you refer to is defined as a text field. The test below is based on this.

A test for a TEXT field's contents being purely numeric is:

GetAsNumber ( Field) = Field

An example:  If a text field contains the value:  1+4

GetAsNumber (1+4) = 14 returns false, therefore the value '1+4' would be excluded for you.

On the other hand, GetAsNumber (18) = 18 returns true, therefore the value '18' would be accepted.

But if your field is defined as a number field, a more stringent test needs to be used such as:

GetAsNumber ( Field) = Field and Length(GetAsNumber ( Field)) = Length(Field)

Ralph

Edited by NLR
  • Like 1
Posted

You might also try the Filter Funtion

Filter ( yourField ; "0123456789" )

  • Like 1
Posted
On 7/10/2018 at 6:18 PM, rwoods said:

Hi Eli

I know someone will have a better answer than this, but my thoughts would be 

1) Make the field type be 'number' and use the fields options validation set to 'Strict Data Type = Numeric'

2) If the field has to be a text field, but you want to check that it is numeric, the you could do something like :-
 


FieldIsNumber = If ( Filter ( numberField ; "0123456789" ) = numberField ; 1 ; 0 )

This Boolean result would be 1 if the field only contained numerals. It would give a positive result for '01234', but this may be OK.

FieldIsNumber would return false for 1.0 (or 1,5 depending on your language) so make sure you include the dot and/or comma as well in the filter.

This topic is 2346 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.