Or regular expression (resolved)

the root of the problem lies in my carelessness, but there is something wrong with the port check I wrote. In the end, the numeric range check is used, which is very simple. Thank you for your comments for your good ideas. Thank you all for your good ideas.

verify that the expression is correct on the online test tool, but it is wrong in the project, such as the test port number

let checkPort = (rule, value, callback) => {
        if (value.length < = 0) {
          return callback(new Error(""));
        }
        setTimeout(() => {
          if (value == "" || typeof(value) == undefined) {
            callback(new Error(""));
          } else {
            const re = /^[1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]{1}|6553[0-5]$/;
            const rsCheck = re.test(value);
            if (!rsCheck) {
              callback(new Error("[0-65535]"));
            } else {
              callback();
            }
          }
        }, 1000);

(according to the great god who made the comments below, change! value to value.length, will appear the loading status that has been checked all the time) will be displayed as follows, feeling very toxic

.

clipboard.png


value

clipboard.png

is there any divine guidance


the first of your rules is like this

clipboard.png

!value.length

clipboard.png


the first one is not regular, and it is impossible to judge the port number. Input such as 22221342sd3 will also judge whether the br is successful
but the error message displayed on the interface has nothing to do with the regular match. It is certain that the port number is an integer value somewhere else, so it is the easiest to judge by converting it to an integer value. It is actually inconvenient to use the regular formula.
and you actually check that the required port number is not in the range of 0-65535.
the second one is better judged by value.length. Do you want to enter a space?

Menu