web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Validating Text Field in IP address Format

(0) ShareShare
ReportReport
Posted on by 334

I have a requirement to validate a text field to an IP address format,

I have seen the java script , and i have created the web resource but the validation fails even when I type a correct IP address. Here is the code below

function format_ipaddress(fieldName)
{
	 var ipaddress = Xrm.Page.data.entity.attributes.get(fieldName).getValue();
     var ipformat =/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/; 	
		
	if ((ipaddress != "") && (ipaddress != null))
	{
	   if (ipaddress == ipformat) 
	{
		ipaddress = ipaddress;
	}
		else 
		{
			alert ("Invalid IP address format");
			ipaddress = "000.000.000.000";	
		}
		
		Xrm.Page.data.entity.attributes.get(fieldName).setValue(ipaddress);
	}
}


Even if I type a correct IP address i still get an Invalid Ip address format.

Is something wrong with the regex expression.

Regards.

*This post is locked for comments

I have the same question (0)
  • lawix10 Profile Picture
    334 on at
    RE: Validating Text Field in IP address Format

    Thanks this was the right answer.

    Regards.

  • lawix10 Profile Picture
    334 on at
    RE: Validating Text Field in IP address Format

    Thanks, but I went for another method

  • Verified answer
    Gopalan Bhuvanesh Profile Picture
    11,401 on at
    RE: Validating Text Field in IP address Format
    Hi
    Please try the following:


    function format_ipaddress(fieldName) {
        var ipaddress = Xrm.Page.data.entity.attributes.get(fieldName).getValue();
        var ipformat = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
    
        if ((ipaddress != "") && (ipaddress != null)) {
            if (!ipaddress.match(ipformat)) {
                Xrm.Utility.alertDialog("Invalid IP address format", null)
                ipaddress = "000.000.000.000";
                Xrm.Page.data.entity.attributes.get(fieldName).setValue(ipaddress);
            }
        }
    }







  • Verified answer
    M.Azwar Alam Profile Picture
    on at
    RE: Validating Text Field in IP address Format

    Hi

    You can check following method.I got it from following blog.

    www.w3resource.com/.../ip-address-validation.php

    1. function ValidateIPaddress(inputText)  
    2.  {  
    3.  var ipformat = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;  
    4.  if(inputText.value.match(ipformat))  
    5.  {  
    6.  document.form1.text1.focus();  
    7.  return true;  
    8.  }  
    9.  else  
    10.  {  
    11.  alert("You have entered an invalid IP address!");  
    12.  document.form1.text1.focus();<br>return false;  
    13.  }  
    14.  }  

    Mark asnwer as verified, if it works for you.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Mansi Soni – Community Spotlight

We are honored to recognize Mansi Soni as our August 2025 Community…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#2
Christoph Pock Profile Picture

Christoph Pock 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans