javascript - Find a js regular rule: only numbers and English periods can be entered, not two consecutive dots, and cannot start or end with "."
天蓬老师
天蓬老师 2017-06-12 09:22:18
0
5
1123

Find a regular rule to use for ip fuzzy search in the text boxUse

The correct approximate format is:
1.1
1.11.1
1.1.11

Satisfy the following filter items:
Cannot start with ".": .1.1.11
Cannot end with ".": 1.1.11.
Cannot have 2 consecutive ".": 1. .1.11
cannot contain symbols other than the English period ".": 1@1.1
cannot contain spaces: 1 .1 .1
cannot contain letters or Chinese characters
Only 1 number can pass

Because I am not very good at regular expressions, I use a stupid method to eliminate them step by step. My idea is to first remove the inner and outer spaces:
1. Remove the inner spaces: /^S*$/
2. Remove spaces on both sides:

    while((value.indexOf(" ") == 0) && (value.length > 1)) {
        return false;
    }
    while((value.lastIndexOf(" ") == value.length - 1) && (value.length > 1)) {
        return false;
    }

3. Then exclude symbols: /<|>|||*|?|\|"|/|&|#|@|!|~|(|)/;
4. Remove Chinese The regular rules: /^[u4e00-u9fa5] $/;
It won’t be used later, and I feel that these methods are very cumbersome and redundant. Is there any regular rules that can solve this problem? Thank you!

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(5)
学习ing
/^(((\d+[.])+\d+)|\d)$/
代言
/^((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.){3}(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])$/

Among them, (d|[1-9]d|1dd|2[0-4]d|25[0-5]) is specially used to match numbers from 0 to 255. The above regular expression can Understood as: ([0~255].){3}[0~255]

迷茫

To put it bluntly, it means starting with a number and ending with a number, and you can insert a period in the middle of the number.

/^(\d+[.])+\d+$/

The IP address usually has two dots, so

 /^(\d+[.]){2}\d+$/
仅有的幸福

The IP address is in the format of x.x.x.x. The longest x is a 3-digit integer and does not exceed 255, so my regular expression is as follows:

/^([0-9]|[1-9]d|1dd|2[0-4]d|25[0-5])(.([0-9]|[1-9]d| 1dd|2[0-4]d|25[0-5])){0,3}$/

This part is mainly to match numbers between [0,255]

([0-9]|[1-9]d|1dd|2[0-4]d|25[0-5])

滿天的星座

/^d+(?:.d+)*$/
Has been personally tested to meet the subject’s needs

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template