Obtaining the Number in the String in a Cell by JS

  • Last update:June 30, 2025
  • iconNote:
    The solution introduced in this document only applies to the data entry preview on PC.

    Overview

    Expected Effect

    During data entry report creation, you need to obtain numbers in strings dynamically, as shown in the following figure.

    动图1 - Copy.gif

    Implementation Method

    To realize the effect, you can add an After Exiting Edit event for a text widget. For details about the API description, see JS API Summary.

    iconNote:
    The effect cannot be previewed on mobile terminals.

    Example

    Report Design

    1. Create a built-in dataset named Embedded1, as shown in the following figure.

    1.png

    2. Design the table as shown in the following figure. Add a text widget for cell A2.

    2.png

    3. Select cell A2, add an After Exiting Edit event, add a parameter row, and set the parameter value to the formula row(), as shown in the following figure.

    3.png

    The JavaScript code is as follows.

    iconNote: 
    The regular expression in this code is used to match numbers. In actual application, if you match other content, replace the regular expression with an appropriate one.
    var str = this.getValue();
    //Obtain the current value of the text box widget.
    var num = str.replace(/[^0-9]/ig, "");
    //Extract the number by the regular expression.
    _g().setCellValue(1, row-1, num);
    //Assign the value (the number extracted above) to cell B2.

    Effect Display

    Save the report. After clicking Data Entry Preview, modify the values in the text boxes. The numbers after modifications in the current cells will be obtained in the corresponding cells, as shown in the following figure.

    动图1.gif

    iconNote:
    The effect cannot be previewed on mobile terminals.

    Template Download

    For details, you can download the template Obtaining the Number in the String in a Cell by JS.cpt.

    Attachment List


    Theme: Data Entry
    Already the First
    Already the Last
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    10s後關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy