Verification to be only numbers in text field

Good day
I have an single textbox. I need to verify that in that field must be only numbers (only phone number).
How i can get it ?

P.S at the begin i made mistake instead of number type a create string. Now my list have many items and if i change in list setting to number it erase all data in all items in this text field.

Dear @ixxxl,
It should be quite simple, you can add any kind of validator to any field. For example, if you want to make sure that it only has digits, you can add the following to JS editor, just change it from 'Title' to the name of whatever field you want to validate:

fd.spRendered(function(){
  fd.field('Title').validators.push({
    name: 'Phone number validator',
    error: 'Please, enter a phone number with only digits',
    validate: function(value) {
        return value.match(/\d/g);
    }
  });
});

@Nikita_Kurguzov
hi , it works , but when it is only text
image
when i combine it with numbers it doesn't say error
image

Dear @ixxxl,
Okay, my bad, this should work better:

fd.spRendered(function(){
  fd.field('Title').validators.push({
    name: 'Phone number validator',
    error: 'Please, enter a phone number with only digits',
    validate: function(value) {
        return value.match("^[0-9]*$");
    }
  });
});
1 Like

@Nikita_Kurguzov
Thank you, works good!!

1 Like