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

Notifications

Announcements

No record found.

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)
  • Verified answer
    M.Azwar Alam Profile Picture
    on at

    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.

  • Verified answer
    Gopalan Bhuvanesh Profile Picture
    11,401 on at
    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);
            }
        }
    }







  • lawix10 Profile Picture
    334 on at

    Thanks, but I went for another method

  • lawix10 Profile Picture
    334 on at

    Thanks this was the right answer.

    Regards.

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans