ValidNr ( )

Function stats

Average user rating
251
259
9999
Support
FileMaker 9.0 +
Date posted
18 June 2010
Last updated
19 June 2010
Version
Recursive function
No

Author Info
 J.C. Roeloffzen

1 functions

Average Rating None

author_avatar



 

Function overview

Prototype

ValidNr  ( nr )


Parameters

nr  


Description

Tags:  numbers  

Test field on invalid characters, empty values and even the result of erroneous calculations (e.g. division by zero).
Function returns zero is the number is valid.
E-notation is not supported. This function also does not test on decimal points of commas.

Examples

Sample input

1. ValidNr (evaluate (lg (-9))) ;
2: ValidNr (158.36)
3: ValidNr(Evaluate (Case(1=2; 0)))


Sample output

1: result = -2 (Logarithm of negative number does not exist)
2: result = 0 (this means that the number is valid)
3: result = 1 (number is empty)

 

Function code

/* Function ValidNr(nr)

Function tests on usability of number.

Function returns 0 if nr is valid;
+1 if nr is empty,
-1 is nr has nonnumerical characters,
-2 if nr is unavailable (e.g. the result of division by zero)

J.C. Roeloffzen, 18 jun 2010

feedback to: j.c.roeloffzen@rug.nl
*/

Let([
nrString = Trim(GetAsText(nr))];

Case(
IsEmpty( nrString ); 1;
nr ≠ 0 and nr/nr > 2; -2;
nrString ≠ Filter(nrString; "0123456789+-.,"); -1;
0)
)

// ===================================
/*

    This function is published on FileMaker Custom Functions
    to check for updates and provide feedback and bug reports
    please visit http://www.fmfunctions.com/fid/259

    Prototype: ValidNr( nr )
    Function Author: J.C. Roeloffzen (http://www.fmfunctions.com/mid/251)
    Last updated: 19 June 2010
    Version: 1.1

*/
// ===================================

 

 

 

 


Login or register to comment

Create a new account with fmcustomfunctions.com or login to post a comment.

 

 

 

Top Tags

Text Parsing  (31)
List  (20)
XML  (20)
Date  (19)
Format  (18)
Debug  (12)
Dev  (11)
Variables  (11)
Layout  (11)
Interface  (10)
Text  (10)
Filter  (10)
ValueIterator  (6)
Layout Objects  (6)
Uuid  (6)
HTML  (6)