当前位置:网站首页>格式校验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;
边栏推荐
- php获取cpu使用率、硬盘使用、内存使用
- [PHP是否安装了 SOAP 扩]对于php实现soap代理的一个常见问题:Class ‘SoapClient‘ not found in PHP的处理方法
- PHP obtains some values in the string according to the specified characters, and reorganizes the remaining strings into a new array
- php内的addChild()、addAttribute()函数
- Several keywords in C language
- Grbl software: basic knowledge of simple explanation
- Huawei Hongmeng OS, is it OK?
- 数理统计与机器学习
- Eco express micro engine system has supported one click deployment to cloud hosting
- cookie插件和localForage离线储存插件
猜你喜欢

2022-2-14 learning xiangniuke project - Section 6 displays login information

VSCode paste image插件保存图片路径设置

Appnuim environment configuration and basic knowledge

How to write good code - Defensive Programming Guide

Win10 copy files, save files... All need administrator permission, solution

mysql的约束总结

Pytorch Basics

Software testing Q & A

memcached安装

Regular expression summary
随机推荐
CNN可视化技术 -- CAM & Grad-CAM详解及pytorch简洁实现
JWT工具类
memcached安装
460. LFU cache bidirectional linked list
The Hong Kong Stock Exchange learned from US stocks and pushed spac: the follow-up of many PE companies could not hide the embarrassment of the world's worst stock market
Typora installation (no need to enter serial number)
RGB 无限立方体(高级版)
Some experience of exercise and fitness
Software testing - concept
Eco express micro engine system has supported one click deployment to cloud hosting
《CGNF: CONDITIONAL GRAPH NEURAL FIELDS》阅读笔记
Small and medium-sized projects to achieve certification and authorization of hand filter
ThreadLocal memory leak
JS determines whether the mobile terminal or the PC terminal
PHP read file (read JSON file, convert to array)
Zzuli:1065 count the number of numeric characters
Several keywords in C language
c语言中的几个关键字
[golang syntax] be careful with the copy of slices
深度学习分类网络--Network in Network