1. ip正则表达式验证

Posted on 2017-02-09 16:19  zkx4213  阅读(157)  评论(0编辑  收藏  举报

 

java:

private boolean IsIpAddressValidOrEmpty(String ip) {
  if (ip == null) return false;
  String temp = "^(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])$";
  return ip.matches(temp);
}

 

js:
var temp = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
if (!temp.test(detailIP)) {
mx.indicate("warn", "IP格式错误,请重新输入!");
return;
}

 

 

js:
以http://或https://开头的URL验证:   /(http|https):\/\/([\w.]+\/?)\S*/;
IP地址正则:  /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){3}$/;
 
IP地址+端口正则: /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){3}:([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-5]{2}[0-3][0-5])$/;
http://192.168.1.1:8080或 https://192.168.1.1:8080 正则:/^(http|https):\/\/(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){3}:([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-5]{2}[0-3][0-5])$/;

 

Copyright © 2024 zkx4213
Powered by .NET 9.0 on Kubernetes