Skip to content

Infragistics Community Forum / Web / Ignite UI for Angular / Restrict the user to input negative integer for column of number data type

Restrict the user to input negative integer for column of number data type

New Discussion
Shobhana Suara
Shobhana Suara asked on Jul 20, 2020 6:34 AM

Using igx-data grid.

Scenario: For a particular column of number data type, i want to restrict the user to input any negative integer. User can only input positive integer.

I have used (keydown) event to write the validation but it is not working.

Please hep!!

Sample Stackbliz: https://stackblitz.com/edit/angular-grid-validation?file=src%2Fapp%2Fgrid%2Fgrid-allData-summary%2Fgrid-allData-summary.component.html

Thanks in advance.

Sign In to post a reply

Replies

  • 0
    N. Ishibashi
    N. Ishibashi answered on Jul 17, 2020 5:18 AM

    Hello Shobhana Suara,

    How about this?

    onKeydown(evt: KeyboardEvent, editValue: number) {
     console.log(evt);
      if (evt.keyCode == 189){
        return false;
      }
    }

    Could you give it a try to see whether this works well?

    • 0
      Shobhana Suara
      Shobhana Suara answered on Jul 17, 2020 6:30 AM

      Hello Noriko,

      I tried this piece of code already, it is not restricting the -ve(negative) sign. i have posted the stackbliz above please try in that sample.

      • 0
        Shobhana Suara
        Shobhana Suara answered on Jul 17, 2020 2:55 PM

        I have used this code and it worked. return (event.charCode == 8 || event.charCode == 0) ? null : event.charCode >= 46 && event.charCode <= 57 && event.charCode != 47

      • 0
        N. Ishibashi
        N. Ishibashi answered on Jul 20, 2020 6:34 AM

        Hello,

        Thank you for the update.

        I'm glad to know that you now have a code which works well.

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Shobhana Suara
Favorites
0
Replies
4
Created On
Jul 20, 2020
Last Post
5 years, 7 months ago

Suggested Discussions

Created by

Created on

Jul 20, 2020 6:34 AM

Last activity on

Feb 12, 2026 9:55 AM