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
2165
IP validation
posted

I want to validate an IP address in a cell and provide an input format. How to do that? Please give an example. Thanks.

Parents
No Data
Reply
  • 2165
    Suggested Answer
    Offline posted

    I found the solution but, is there an easier way?

    My solution (simplified):

    @(Html.Infragistics()
                  .Grid(Model.Ips.AsQueryable())
                  .PrimaryKey("Key")
                  .ID("MyGrid")
                  .DataBind()
                  .Columns(pColumn =>
                  {
                      pColumn.For(p => p.Key).Hidden(true);
                      pColumn.For(p => p.Address).HeaderText("IP Address");
                  })
                  .Features(pFeatures =>
                  {
                      pFeatures.Updating()
                          .ColumnSettings(pSettings =>
                          {
                              pSettings
                                  .ColumnSetting()
                                  .ColumnKey("Address")
                                  .Required(true)
                                  .EditorOptions("validatorOptions:{checkValue:validate}");
                          });
                  })
                  .Render()
    )
    function validate(evt, ui) {
            var reg = new RegExp(/\b(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]?)\b/);
            if (!reg.test(ui.value)) {
                ui.message = "Enter a valid IP address";
                return false;
            }
            return true;
    }
Children