Set Data Table Column with Numeric Input Only

Hello,

Is there a way to create validation for numeric only input on one of Data Table column? We can easily set this on Single-line Text fileds and set the Type, but no such control on Data Table field.

Thanks.

Hello @AdityaGiriHertanto,

You can change the input type of the column to Number, so only a numeric value can be entered.

image

Hi @mnikitina,

Tried the number type but this also format the field as number, means input will be treated as number with digit separator not free text.

My input will be 15 digit numeric with 0 as first digit. Is it possible to configure it that way?

Thanks.

Hello @AdityaGiriHertanto,

One option is adding column validation that checks if the input value matches regex expression:

fd.control('DataTable1').addColumnValidator('Column1', {
    error: 'Invalid value',
    validate: function(value) {
      var regex_pattern =/0[0-9]{14}/ ;
      var check = new RegExp(regex_pattern);
      var isValid = check.test(value);

      return isValid;
    }
});

If you consider paid support, we can add a masked input column type to the DataTable. Please email us at support@plumsai.com to know more.

Hi @mnikitina ,

I am following the above solution you posted,it kind of works for me. I am using this for text field validation. Is there a way to get or condition to apply that year must start from 19 or 20?

fd.field('YearofLastLeave').validators.push({
name: 'YearofLastLeave validator',
error: 'Year must start from 19 or 20',
validate: function(value) {
var regex_pattern =/19[0-9]/ ;
var check = new RegExp(regex_pattern);
var isValid = check.test(value);
return isValid;
}
});

Thanks in advance.

Hello @navpreet.kaur,

You can use this RegEx expression in the code to validate the year:

^(19|20)\d{2}$
1 Like

@mnikitina
Thank you so much

1 Like