当前位置:网站首页>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;
边栏推荐
猜你喜欢
ES6的详细注解
[PHP是否安装了 SOAP 扩]对于php实现soap代理的一个常见问题:Class ‘SoapClient‘ not found in PHP的处理方法
如何使用MITMPROXy
ROS2----LifecycleNode生命周期节点总结
Unity Shader 学习笔记(3)URP渲染管线带阴影PBR-Shader模板(ASE优化版本)
数理统计与机器学习
死磕大屏UI,FineReport开发日记
RGB infinite cube (advanced version)
Gcnet: non - local Networks meet Squeeze excitation Networks and Beyond
How vite is compatible with lower version browsers
随机推荐
memcached安装
Go language web development is very simple: use templates to separate views from logic
数理统计与机器学习
STC8H8K系列汇编和C51实战——按键允许按键计数(利用下降沿中断控制)
Cookie plugin and localforce offline storage plugin
Linkage between esp8266 and stc8h8k single chip microcomputer - Weather Clock
1037 Magic Coupon
How vite is compatible with lower version browsers
测试 - 用例篇
PHP 开发与测试 Webservice(SOAP)-Win
Gcnet: non - local Networks meet Squeeze excitation Networks and Beyond
492.构造矩形
Shenji Bailian 3.54-dichotomy of dyeing judgment
《CGNF: CONDITIONAL GRAPH NEURAL FIELDS》阅读笔记
DRM display framework as I understand it
STC8H8K系列汇编和C51实战——数码管显示ADC、按键串口回复按键号与ADC数值
STC8H8K系列匯編和C51實戰——數碼管顯示ADC、按鍵串口回複按鍵號與ADC數值
[whether PHP has soap extensions installed] a common problem for PHP to implement soap proxy: how to handle class' SoapClient 'not found in PHP
Eco express micro engine system has supported one click deployment to cloud hosting
token过期自动续费方案和实现