Brian Dunning's FileMaker Custom Functions

IsIP ( IP )

Checks if string entered is an IP address, returns true or false

  Average rating: 4.4 (31 votes) Log in to vote

Hartger Visser   Hartger Visser
Teuker Small Business Solutions
http://www.teuker.nl

Share on Facebook Share on Twitter

  Sample input:
IsIP (192.168.1.1)
  Sample output:
true

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

Checks wether the values between the "." are between 0 and 255 (including zero, excluding 255).
Also checks if there are 3 periods in the tring.

 

Comments

Tim Cimbura   Tim Cimbura, LuminFire
Apr 29, 2011
I'm not sure this function works. The parsing of the 3rd argument is not correct and should be

GetAsNumber ( Middle ( $IP ; Position ( $IP ; "." ; 1 ; 2 ) + 1 ; Position ( $IP ; "." ; 1 ; 3 ) - Position ( $IP ; "." ; 1 ; 2 ) -1 ) )
 
Andrew Clark   Andrew Clark, Altus Technologies Corporation
Apr 1, 2022
The above function can find a.b.c.d to be a valid IP address as "" = 0 when comparing. Here s an alternative:

Let ( [~IP=Substitute ( IP ; "." ; "¶" );
~IP1 = GetAsNumber(GetValue(~IP;1));
~IP2 = GetAsNumber(GetValue(~IP;2));
~IP3 = GetAsNumber(GetValue(~IP;3));
~IP4 = GetAsNumber(GetValue(~IP;4))];
If ( PatternCount (IP ; "." ) = 3 and
not IsEmpty(~IP1) and
~IP1 ≤ 255 and
~IP1 ≥ 0 and

not IsEmpty(~IP2) and
~IP2 ≤ 255 and
~IP2 ≥ 0 and

not IsEmpty(~IP3) and
~IP3 ≤ 255 and
~IP3 ≥ 0 and

not IsEmpty(~IP4) and
~IP4 ≤ 255 and
~IP4 ≥ 0 ;
1 ;
0 ))
 
Andrew Clark   Andrew Clark, Altus Technologies Corporation
Apr 1, 2022
After further testing, I made two changes:
The first line is now "Let ( [~IP=Substitute (Filter(IP;".0123456789"); "." ; "¶" );
And instead of returning "1" or "0", I return a good IP address or "0" by replacing the 2nd to last line (the "1;") with "~IP1 & "." & ~IP2 & "." & ~IP3 & "." & ~IP4;"
The reason I did this is 255.5a.45.8u was showing as a "1" as the GetAsNumber() ignored the letters. I could strip out the letters with the filter but then IP might not be usable as a valid IP address so instead of returning "1" or "true", I return the address deemed to be valid (in the case above, I would return "255.5.45.8")
 

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 20 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: