当前位置:网站首页>格式校验js
格式校验js
2022-07-02 05:54:00 【Serena_tz】
let util = {};
// 将json格式转成echart data格式
util.jsonToList = function jsonToList(json) {
if (json) {
return Object.keys(json).map(key => {
return {
name: key,
value: json[key]
};
});
}
};
// 手机号格式校验
util.validatephone = function (rule, value, callback, mag, msg) {
if (!value) {
return callback(new Error('手机号不可为空'));
} else if (!/^1[1|2|3|4|5|6|7|8|9][0-9]\d{8}$/.test(value)) {
return callback(new Error('手机号输入错误'));
} else {
callback();
}
};
// 邮箱格式校验
util.validatemail = function (rule, value, callback, mag, msg) {
if (!value) {
return callback(new Error('邮箱不可为空'));
} else if (!(/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/.test(value))) {
return callback(new Error('邮箱输入错误'));
} else {
callback();
}
};
util.singleValidIP = function (str) {
// IP地址合法校验: 排除 0.0.0.0; 排除 255.255.255.255; 支持区间录入
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)) {
// 支持区间录入
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);
}
// //获取url中参数
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;
边栏推荐
- Pytorch Chinese document
- 死磕大屏UI,FineReport开发日记
- Small and medium-sized projects to achieve certification and authorization of hand filter
- Zzuli: maximum Convention and minimum common multiple
- cookie插件和localForage离线储存插件
- 3D 打印机 G 代码命令:完整列表和教程
- all3dp.com网站中全部Arduino项目(2022.7.1)
- 软件测试基础篇
- Lambda 表达式 和 方法引用
- Vscode paste image plugin saves image path settings
猜你喜欢
随机推荐
Résumé de la collection de plug - ins couramment utilisée dans les outils de développement idea
TI毫米波雷达学习(一)
A collection of commonly used plug-ins for idea development tools
Technologists talk about open source: This is not just using love to generate electricity
all3dp. All Arduino projects in com website (2022.7.1)
Opencv LBP features
“简单”的无限魔方
Eco express micro engine system has supported one click deployment to cloud hosting
Alibaba: open source and self-developed liquid cooling data center technology
Several keywords in C language
1035 Password
PHP 开发与测试 Webservice(SOAP)-Win
460. LFU cache bidirectional linked list
Summary of MySQL constraints
Zzuli:1060 numbers in reverse order
CNN可视化技术 -- CAM & Grad-CAM详解及pytorch简洁实现
测试 - 用例篇
Zzuli: maximum Convention and minimum common multiple
php内类名称与类内方法名相同
MySQL transaction and isolation level









