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)