Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
315
MaskEditor ValidatorOptions for IP Address
posted

C#/MVC4 Application

I'm attempting to create an IP address input that will be validated. I'm using a MaskEditor as follows:

@Html.Infragistics().MaskEditorFor(m => m.DeviceIpAddress).InputMask("099.099.099.099").ValidatorOptions(o => o.AnimationShow(500).OnSubmit(true).OnBlur(true).OnChange(true).FormSubmit(true).RegExp(@"^(([1-9]?\d|1\d\d|25[0-5]|2[0-4]\d)\.){3}([1-9]?\d|1\d\d|25[0-5]|2[0-4]\d)$").CustomErrorMessage("IP address not valid").Required(false)).Render()

The validation is not working as expected - even with a valid IP address (e.g. 192.168.100.100) it raises a validation error.

I know the RegEx "^(([1-9]?\d|1\d\d|25[0-5]|2[0-4]\d)\.){3}([1-9]?\d|1\d\d|25[0-5]|2[0-4]\d)$" is valid as I've written a jQuery function to test it, which works as expected:

$("#btnValidateTest").click(function (e) {
var ipAddress = $("#DeviceIpAddress").igEditor("value").replace(/ /g, '');
var ipAddressRegex = /^(([1-9]?\d|1\d\d|25[0-5]|2[0-4]\d)\.){3}([1-9]?\d|1\d\d|25[0-5]|2[0-4]\d)$/;

if (ipAddress.match(ipAddressRegex) == null) {
alert("ip address NOT valid");
}
else
{
alert("ip address valid");
}
});

I've also validated the RegEx on an online checker (http://www.freeformatter.com/regex-tester.html) and it works as expected.

To rule out the issue being with the MaskEditor I also tried using a TextEditor, but I see the same issue:

@Html.Infragistics().TextEditor("Test").ValidatorOptions(o => o.AnimationShow(500).OnSubmit(true).OnBlur(true).OnChange(true).FormSubmit(true).RegExp(@"^(([1-9]?\d|1\d\d|25[0-5]|2[0-4]\d)\.){3}([1-9]?\d|1\d\d|25[0-5]|2[0-4]\d)$").CustomErrorMessage("IP address not valid").Required(false)).Render()

I'm using 2013.2 of the IgniteUI controls.

Regards,
Dave