cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
h_zamzam
Regular Visitor

IP Address Text Input Validation

Hi,

 

I'm trying to validate the IP address with IsMatch function but I don't seem to find a straight forward way to do it. The text input validation should be as follows. 

 

Ex. 10.9.8.7/24

 

10= 1st octet values 1-255

9= 2nd octet values 0-255

8= 3rd octet values 0-255

7= 4th octet values 0-255

/24= Subnet mask (normally this value range can be 8-32)

 

Appreciate any help, please.

Thanks,

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
v-bofeng-msft
Community Support
Community Support

Hi @h_zamzam ,

 

Please try:

 

With(
    {IPAddress:"1.9.8.7/24"},
    With(
        {OctetString:First(Split(IPAddress,"/")).Result,SubnetMask:Int(Last(Split(IPAddress,"/")).Result)},
        (SubnetMask<=32 && SubnetMask>=8) &&
        Sum(ForAll(
            Split(IPAddress,".").Result As A,
            {Count:If(Int(A.Result)<0 Or Int(A.Result) >255,1,0)}
        ),Count)=0 &&
        First(Split(IPAddress,".").Result).Result <> "0"
    )
)

 

Best Regards,

Bof

View solution in original post

4 REPLIES 4
phipps0218
Super User
Super User

You can use IsMatch then add your RegEx formula to ensure it is an IP Address. This Regex will give you the following:
\b((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(?:(?<!\.)\b|\.)){4}

phipps0218_0-1658235810012.png

Hope this helps.

Please Accept as Solution if it solves your question. Or just give it a Thumbs Up if it is helpful as can help others.

LinkedIn: https://www.linkedin.com/in/charlie-phipps-%F0%9F%91%A8%E2%80%8D%F0%9F%92%BB-91338715b/
Subscribe to my YouTube: https://www.youtube.com/channel/UChmFBGU1YKIU91sNMQ7buGg
Twitter: https://twitter.com/phipps0218



 

Try this: \b((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(?:(?<!\.)\b|\.)){4}/.{2}

Ismael_Novo
Resolver II
Resolver II

Hello h_zamzam.

 

This validation is slightly complex. In my knowledge, functions like IsMatch using regular expressions will be able to check the formatting but not the < 256 or > 1 type limits on some fields. (Or maybe are too complex to read for novices). My advice is to approach these problems as if it were excel in multiple steps, which allows you to debug and search for errors much easier in the future.

 

Note: I use European sintaxis so you must replace ";" for ",". Assuming the IP and temporal validations are in labels the recipe is:

 

A) With this function in a Label field we can check the SubNet:

With({Subnet:Value(Last(Split(LabelIPFull.Text;"/")).Result)};If(Subnet>7 And Subnet<33; true ; false ))

B) With this you can catch in other Labels the intermediate values:

With({
digit: Value(Last(FirstN(Split(LabelIP.Text;".");1)).Result)
};
If(digit > 0 And digit < 256;true;false)
)

C) Finally we make an AND of everything to verify that all the conditions are fulfilled. In this way any new need can be addressed in a simple way without having very large or complex formulas.

If(LabelSubNet.Text And LabelIP_1.Text And LabelIP_2.Text And LabelIP_3.Text And LabelIP_4.Text;true;false)

Best regards.

v-bofeng-msft
Community Support
Community Support

Hi @h_zamzam ,

 

Please try:

 

With(
    {IPAddress:"1.9.8.7/24"},
    With(
        {OctetString:First(Split(IPAddress,"/")).Result,SubnetMask:Int(Last(Split(IPAddress,"/")).Result)},
        (SubnetMask<=32 && SubnetMask>=8) &&
        Sum(ForAll(
            Split(IPAddress,".").Result As A,
            {Count:If(Int(A.Result)<0 Or Int(A.Result) >255,1,0)}
        ),Count)=0 &&
        First(Split(IPAddress,".").Result).Result <> "0"
    )
)

 

Best Regards,

Bof

Helpful resources

Announcements
Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Top Kudoed Authors
Users online (1,356)