// 校验IP
export function isValidIP(ip) {
var reg =
/^(\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 reg.test(ip);
}
// 子网掩码校验
export function isSubnetMask(num) {
let reg = /^(\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}$/
return reg.test(num);
}
// 网关校验
export function isGateway(gateway) {
let reg = /^(192\.168(\.(\d|([1-9]\d)|(1\d{2})|(2[0-4]\d)|(25[0-5]))){2})$/;
return reg.test(gateway);
}
// 匹配国内外邮箱号
export function emailAddress(email) {
let re = /^\w+(?:\.\w+){0,1}@[a-zA-Z0-9]{2,14}(?:\.[a-z]{2,4}){1,2}$/;
return re.test(email)
}
// 返回所选时间date的后day 天 当前时间不足day天 则返回当前时间
export function getNextDate(date, day) {
const currentDate = new Date(); // 当前日期
const inputDate = new Date(date); // 给定日期
inputDate.setDate(inputDate.getDate() + day); // 计算指定天数后的日期
if (inputDate > currentDate) { // 判断是否需要返回当前日期
const y = currentDate.getFullYear();
const m = (currentDate.getMonth() + 1).toString().padStart(2, '0');
const d = currentDate.getDate().toString().padStart(2, '0');
return `${y}-${m}-${d}`;
}
const y = inputDate.getFullYear();
const m = (inputDate.getMonth() + 1).toString().padStart(2, '0');
const d = inputDate.getDate().toString().padStart(2, '0');
return `${y}-${m}-${d}`;
}
// 获取当前日期前后的day ,day传负数就是向前
export function getagoAndNextDate(date, day) {
var dd = new Date(date);
dd.setDate(dd.getDate() + day);
var y = dd.getFullYear();
var m = dd.getMonth() + 1 < 10 ? "0" + (dd.getMonth() + 1) : dd.getMonth() + 1;
var d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();
return y + "-" + m + "-" + d;
}