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
Hello,
I am just following to see if there is something else that I could do for you.
Could you please tell me how your value is formed, I have created a sample where I pass a string IP address to the view that will be loaded into the editor like:
Also My Regax expression is:
Model:
The important here will be the InputMask, we will need to configure input mask that will allow us to type only one 0 and one 1.
Looking forward to hearing from you.
Yes my objective is now to be able to validate the input without the prompt characters ("_") being taken into consideration.
So instead of validating 192.168.0__.1__ it would validate 192.168.0.1.
Regards,
Dave
Hey dogle,
Thank you for contacting us.
You do not need to specify the PromptChar, the default prompt character is the underscore. Also the default PadCharacter is the space character (' '). About your requirement, you want to create a mask like IP address, right? And also when validation the input, to ignore the underscore?
Related references:
https://ko.infragistics.com/community/blogs/b/taz_abdeali/posts/understanding-mask-options-in-jquery-mask-editor
http://help.infragistics.com/Help/Doc/LightSwitch/2012.2/CLR4.0/HTML/MaskedEditor_Using_Infragistics_Masked_Editor.html
After further investigation I've found something that will do the job:
@Html.Infragistics().MaskEditorFor(m => m.DeviceIpAddress).InputMask("099.099.099.099").DataMode(MaskEditorDataMode.RawTextWithRequiredPromptsAndLiterals).PadCharacter('_').PromptCharacter('_').ValidatorOptions(o => o.AnimationShow(500).OnSubmit(true).OnBlur(true).OnChange(false).FormSubmit(true).RegExp(@"^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\\_*.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\\_*.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\\_*.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\\_*$").CustomErrorMessage("IP address not valid").Required(false)).Render()
It seems the PromptCharacters are used during the comparison. This regEx allows for PromptCharacters ('_' in this case).
Is there a way for the ValidatorOptions to ignore the PromptCharacters? So instead of validating 192.168.0__.1__ it would validate 192.168.0.1.