当前位置:网站首页>Format check JS
Format check JS
2022-07-02 06:00:00 【Serena_ tz】
let util = {};
// take json Format to echart data Format
util.jsonToList = function jsonToList(json) {
if (json) {
return Object.keys(json).map(key => {
return {
name: key,
value: json[key]
};
});
}
};
// Mobile phone number format verification
util.validatephone = function (rule, value, callback, mag, msg) {
if (!value) {
return callback(new Error(' Mobile phone number cannot be empty '));
} else if (!/^1[1|2|3|4|5|6|7|8|9][0-9]\d{8}$/.test(value)) {
return callback(new Error(' Mobile phone number input error '));
} else {
callback();
}
};
// Mailbox format verification
util.validatemail = function (rule, value, callback, mag, msg) {
if (!value) {
return callback(new Error(' Mailbox cannot be empty '));
} else if (!(/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/.test(value))) {
return callback(new Error(' Mailbox input error '));
} else {
callback();
}
};
util.singleValidIP = function (str) {
// IP Address legal verification : exclude 0.0.0.0; exclude 255.255.255.255; Support interval entry
let reg = /^((25[0-5]|2[0-4]\d|[1]{1}\d{1}\d{1}|[1-9]{1}\d{1}|\d{1})($|(?!\.$)\.)){4}$/;
let regS = /^((25[0-5]|2[0-4]\d|[1]{1}\d{1}\d{1}|[1-9]{1}\d{1}|\d{1})($|(?!\.$)\.))$/;
let regZ = /(^0{1,3}(\.0{1,3}){3}$)/;
let regM = /(^255(\.255){3}$)/;
if (/([-])/.test(str)) {
// Support interval entry
let arr = str.split('-');
if (arr.length === 2) {
return reg.test(arr[0]) && regS.test(arr[1]);
} else {
return false;
}
} else {
return reg.test(str) && !regZ.test(str) && !regM.test(str);
}
};
util.getSessionStorage = function (key) {
if (sessionStorage.getItem(key)) {
let data = sessionStorage.getItem(key);
try {
return JSON.parse(data);
} catch (e) {
return data;
}
}
return '';
}
util.setSessionStorage = function (key, data) {
if (typeof data === 'undefined') {
data = '';
}
data = JSON.stringify(data);
sessionStorage.setItem(key, data);
}
util.removeStorageData = function (key) {
sessionStorage.removeItem(key);
}
// // obtain url In the parameter
util.getUrlParam = function (name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null) return decodeURI(r[2]);
return null;
}
export default util;
边栏推荐
- Problems encountered in uni app development (continuous update)
- 1036 Boys vs Girls
- JWT tool class
- 数据库学习总结5
- Go 学习笔记整合
- Stc8h8k series assembly and C51 actual combat - keys allow key counting (using falling edge interrupt control)
- Picture clipping plug-in cropper js
- Go learning notes integration
- Shenji Bailian 3.52-prim
- Stc8h8k Series Assembly and c51 Real combat - NIXIE TUBE displays ADC, Key Series port reply Key number and ADC value
猜你喜欢
Brain and cognitive neuroscience matlab psychoolbox cognitive science experimental design - experimental design 4
Practice C language advanced address book design
深度学习分类网络--VGGNet
Stick to the big screen UI, finereport development diary
Conglin environmental protection rushes to the scientific and Technological Innovation Board: it plans to raise 2billion yuan, with an annual profit of more than 200million yuan
Go language web development is very simple: use templates to separate views from logic
Software testing - concept
Zabbix Server trapper 命令注入漏洞 (CVE-2017-2824)
在uni-app中引入uView
Redis key value database [primary]
随机推荐
文件包含漏洞(一)
Common websites for Postgraduates in data mining
Keepalived installation, use and quick start
Redis key value database [seckill]
[leetcode] day92 container with the most water
memcached安装
php读文件(读取json文件,转换为数组)
格式校验js
mysql的约束总结
keepalived安装使用与快速入门
[C language] simple implementation of mine sweeping game
php按照指定字符,获取字符串中的部分值,并重组剩余字符串为新的数组
servlet的web.xml配置详解(3.0)
Go learning notes integration
Stick to the big screen UI, finereport development diary
死磕大屏UI,FineReport开发日记
外部中断无法进入,删代码再还原就好......记录这个想不到的bug
Happy Lantern Festival | Qiming cloud invites you to guess lantern riddles
all3dp. All Arduino projects in com website (2022.7.1)
ROS2----LifecycleNode生命周期节点总结