July 10, 20187 yr 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.
July 10, 20187 yr 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 July 10, 20187 yr by rwoods
July 10, 20187 yr 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 July 10, 20187 yr by NLR
July 11, 20187 yr Author Thanks everyone for all the suggestions, these are all very helpful and have solved my problem. Really appreciate it!
July 11, 20187 yr 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.
July 11, 20187 yr Good point @OlgerDiekstra It certainly needs the decimal delimiter in the Filter list!
Create an account or sign in to comment