This question already has an answer here:
这个问题在这里已有答案:
- Regular expression for IP Address Validation 17 answers
- IP地址验证的正则表达式17答案
Please help me out I want to use the regular expression for IP address in that expression it should take only number not Alphabet text
请帮帮我,我想在该表达式中使用正则表达式的IP地址,它应该只采用数字而不是字母文本
suppose my IP Address is like that 111.111.1.111
假设我的IP地址与111.111.1.111类似
When the user enter the IP address then starting it should take 3 number then dot like that goes on
当用户输入IP地址然后启动它应该采取3个数字然后点继续
i used these expression which help to stop writing Alphabet
我用这些表达有助于停止写字母
if ("" != this.value.replace(/((^|\.)((25[0-5])|(2[0-4]\d)|(1\d\d)|([1-9]?\d))){4}$/g, '')) {
this.value = this.value.replace(/[^0-9\.]/g, '');
}
1 个解决方案
#1
3
Use this:
用这个:
\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b
#1
3
Use this:
用这个:
\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b