赶快收藏起来,以备不时之需~
取IP
let url = 'http://123.234.123.111:80/www/ASRfiles/ts/Server/2021/3/25/1015.mp4'
//取ip
let newUrl = url.substr(url.indexOf('//') + 2, url.indexOf(':', url.indexOf(':') + 1) - (url.indexOf('//') + 2))
//取ip前面的 http://
let topUrl = url.substr(0, url.indexOf('//') + 2)
//取ip后面的 :80/www/ASRfiles/ts/Server/2021/3/25/1015.mp4
let bottomUrl = url.substr(url.indexOf(':', url.indexOf(':') + 1))
console.log(topUrl + newUrl + bottomUrl == url) //true
取键值对
/**获取url问号"?"后面键值对
* @param {String} url
*/
export const GetRequest = url => {
// let url = window.location.href;
let theRequest = {
};
if (url.indexOf("?") != -1) {
let a =url.indexOf("?");
let b;
if(url.indexOf("#") != -1){
b =url.indexOf("#");
if(a>b){
b= url.length
}
}
let data=url.substring(a,b);
let str = data.substr(1);
let strs = str.split("&");
for(let i = 0; i < strs.length; i ++) {
theRequest[strs[i].split("=")[0]]=(strs[i].split("=")[1]);
}
}
return theRequest;
}
手机号脱敏
// 手机号 移动电话脱敏 158 **** 8888
export function mobile (str) {
if (!!str) {
var pat = /(\d{3})\d*(\d{4})/;
return str.replace(pat, '$1****$2');
} else {
return "";
}
}
电话号脱敏
// 手机号 移动电话脱敏 010-*****07
export function telphone (str) {
if (!!str) {
var pat = /(\d{4})\d*(\d{2})/;
return str.replace(pat, '$1****$2');
} else {
return "";
}
}
身份证脱敏
export function idCard (str) {
if (!!str) {
return str.replace(/(\w{4})\w*(\w{4})/, '$1********$2');
} else {
return ""
}
}
银行卡号脱敏
export function bankCard (str) {
if (!!str && str.length > 8) {
return `${
str.substring(0, 4)} ${
"*".repeat(str.length - 8).replace(/(.{
4})/g, `$1 `)}${
str.length % 4 ? " " : ""}${
str.slice(-4)}`;
} else {
return ""
}
}
校验身份证号
/*校验15位或18位的身份证号码*/
export function checkIdCardNo(idCardNo) {
//15位和18位身份证号码的基本校验
var check = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(idCardNo);
return check;
}