JS realizes verification of widget value

  • Last update:  2021-06-01
  • I. Overview

    1. Application scenario

    It is hoped that after entering the value in the data entry widget, the verification will be carried out in a timely manner. If there is a problem, a prompt will pop up and the input value will be cleared. The example shown in the figure is that the input string must conform to the format set by the regular expression. If the format is not satisfied, a warning reminder will pop up, as shown in the figure below.

    In specific applications, you can formulate corresponding verification rules according to your needs.

    1.gif


    2. Realization idea

    In the edit end event of the widget, use the test method of JS to determine whether the value of the widget matches the regular expression. If it does not match, clear the input value.

    II. Example

    1. Design template

    Enter Number: in cell A1, and add a Text Field widget in cell B1, as shown below:

    2.png


    2. Add edit end event

    Select the text field widget in cell B1 and add an edit end event to the widget, as shown in the following figure:

    3.png

    The JavaScript code is as follows:

    var ch = this.getValue();
    var patrn = /\s*[0-9]{4,9}\s*$/;
    //Use regular expressions to define rules: The requirement must be a number and no less than four digits
    if (!patrn.test(ch)) {
    FR.Msg.alert("Tip", "The format is wrong, it must be a number and no less than four digits, the correct format is such as: 12345");
    this.setValue("");
    }

    2.3 Preview effect

    Save and click Data Entry Preview, if the content entered in the text box does not meet the rules, a warning will pop up, as shown in I.1.

    Note: Mobile terminal is not supported.

    III. Download template

    Click to download:

    JS_timely_verification.cpt


    Attachment List


    Theme: Data Entry
    • 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