Allow only numeric value in a cell (100.00)

Posted by: jonathanlau2828 on 5 March 2019, 10:00 pm EST

  • Posted 5 March 2019, 10:00 pm EST

    Hi,

    How do we restrict the users to type only numeric value (e.g. 999.00) in a cell?

  • Replied 6 March 2019, 10:24 pm EST

    Hi,
    Please refer to the following demo sample to allow the enter the numeric fields only:
    https://demos.componentone.com/Spread/ASPNET/ControlExplorer_V12E/samples/EditModeFormat/Overview.aspx

    Regards,
    Manish Gupta
  • Replied 12 March 2019, 12:04 am EST

    Hi Manish,

    Thanks for the demo sample link. However, we want to restrict the users from entering non-numeric values in the key press event itself. Any suggestion how it can be implemented?

    Regards,
    Kamal
  • Marked as Answer

    Replied 13 March 2019, 12:17 am EST

    Hi Kamal,
    You may handle the EditStart client-side event and handle the keyup event and replace the nonnumeric value with "".
    Please refer to the following code snippet:


      <script>
    function EditStart(s) {
    setTimeout(function () {
    s.cell.querySelector("input").addEventListener("keyup", function (e) {
    var val = this.value;
    console.log(val)
    this.value=val.replace(/[^\0-9]/ig, "");

    },true)
    })
    }
    </script>

    <FarPoint:FpSpread ID="FpSpread1" runat="server" ClientEvents-EditStart="EditStart" Height="200" Width="400">
    ...
    </FarPoint:FpSpread>



    Please refer to the attached sample for reference.

    Regards,
    Manish Gupta

    Spread-allowNumeric-value-only.zip
  • Replied 20 March 2019, 8:38 pm EST

    Hi Manish,

    The sample you provided solved our problem. Thank you.

    Regards,
    Kamal
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels