js-wrench
Version:
JS函数库
243 lines (224 loc) • 9.41 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: check.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: check.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/**
* @description 正则验证 使用单例
*
* @class CheckRegExp
*/
class CheckRegExp {
constructor() { }
/**
* @description 获取实例
*
* @static
* @return {*}
* @memberof CheckRegExp
*/
static getInstance() {
if (!this.$instance)
this.$instance = new CheckRegExp();
return this.$instance;
}
/**
*
* @description 匹配手机号码
*
* @param {*} v 要匹配的内容
* @return {*} {boolean} 返回一个布尔值
* @memberof CheckRegExp
* @example mobile(12345678) => return false
*/
mobile(v) {
let reg = /^1[3|4|5|6|7|8|9][0-9]{9}$/;
return reg.test(v);
}
/**
*@description 匹配座机
*
* @param {*} v 要匹配的内容
* @return {*} {boolean} 返回一个布尔值
* @memberof CheckRegExp
* @example telephone("1367894517") => false
*/
telephone(v) {
let reg = /^(0\d{2,3}-\d{7,8})(-\d{1,4})?$/;
return reg.test(v);
}
/**
* @description 匹配密码 密码以字母开头,长度在6~18之间,只能包含字母、数字和下划线
*
* @param {*} v 要匹配的内容
* @return {*} {boolean} 返回一个布尔值
* @memberof CheckRegExp
* @example password("abc!@") => false
*/
password(v) {
let reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
return reg.test(v);
}
/**
* @description 匹配QQ号码
*
* @param {*} v 要匹配的内容
* @return {*} {boolean} 返回一个布尔值
* @memberof CheckRegExp
* @example qq("12345") => false
*/
qq(v) {
let reg = /^[1-9][0-9]{4,9}$/;
return reg.test(v);
}
/**
* @description 匹配身份证号码
*
* @param {*} v 要匹配的内容
* @return {*} {boolean} 返回一个布尔值
* @memberof CheckRegExp
* @example IDcard("2313213213") => false
*/
IDcard(v) {
let reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
return reg.test(v);
}
/**
* @description 匹配邮政编码
*
* @param {*} v 要匹配的内容
* @return {*} {boolean} 返回一个布尔值
* @memberof CheckRegExp
* @example postal("511740") => true
*/
postal(v) {
let reg = /\d{6}/;
return reg.test(v);
}
/**
* @description 匹配URL
*
* @param {*} v 要匹配的内容
* @return {*} {boolean} 返回一个布尔值
* @memberof CheckRegExp
* @example url("http://127.0.0.1") => true url("http://www.abc.com") => true
*/
url(v) {
let reg = /(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/;
return reg.test(v);
}
/**
* @description 匹配IP
*
* @param {*} v 要匹配的内容
* @return {*} {boolean} 返回一个布尔值
* @memberof CheckRegExp
* @example IPv4("127.0.0.1") => true
*/
IPv4(v) {
let reg = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
return reg.test(v);
}
/**
* @description 匹配数字
*
* @param {*} v 要匹配的内容
* @return {*} {boolean} 返回一个布尔值
* @memberof CheckRegExp
* @example number("123") => true number("s1") => false
*/
number(v) {
let reg = /^[0-9]$/;
return reg.test(v);
}
/**
* @description 匹配英文
*
* @param {*} v 要匹配的内容
* @return {*} {boolean} 返回一个布尔值
* @memberof CheckRegExp
* @example en("cn") => true
*/
en(v) {
let reg = /^[a-zA-Z]+$/;
return reg.test(v);
}
/**
* @description 匹配中文
*
* @param {*} v 要匹配的内容
* @return {*} {boolean} 返回一个布尔值
* @memberof CheckRegExp
* @example cn("中文") => true cn("cn") => false
*/
cn(v) {
let reg = /^[\u4E00-\u9FA5]+$/;
return reg.test(v);
}
/**
* @description 匹配HTML标签
*
* @param {*} v 要匹配的内容
* @return {*} {boolean} 返回一个布尔值
* @memberof CheckRegExp
* @example html("<div></div>") => true
*/
html(v) {
let reg = /<("[^"]*"|'[^']*'|[^'">])*>/;
return reg.test(v);
}
/**
* @description 匹配邮箱地址
*
* @param {*} v 要匹配的内容
* @return {*} {boolean} 返回一个布尔值
* @memberof CheckRegExp
* @example email("1324568@qq.com") => true
*/
email(v) {
let reg = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
return reg.test(v);
}
/**
* @description 匹配账号合法
*
* @param {*} v 要匹配的内容
* @return {*} {boolean} 返回一个布尔值
* @memberof CheckRegExp
* @example username(abc_132) => true
*/
username(v) {
let reg = /^[a-zA-Z][a-zA-Z0-9_]{4,15}$/;
return reg.test(v);
}
}
const check = CheckRegExp.getInstance();
export default check;
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="CheckRegExp.html">CheckRegExp</a></li><li><a href="Format.html">Format</a></li></ul><h3>Global</h3><ul><li><a href="global.html#bind">bind</a></li><li><a href="global.html#debounce">debounce</a></li><li><a href="global.html#deepCopy">deepCopy</a></li><li><a href="global.html#each">each</a></li><li><a href="global.html#empty">empty</a></li><li><a href="global.html#extend">extend</a></li><li><a href="global.html#getBrowserType">getBrowserType</a></li><li><a href="global.html#getUID">getUID</a></li><li><a href="global.html#getVerifyCode">getVerifyCode</a></li><li><a href="global.html#has">has</a></li><li><a href="global.html#includes">includes</a></li><li><a href="global.html#indexOf">indexOf</a></li><li><a href="global.html#isAndroid">isAndroid</a></li><li><a href="global.html#isArray">isArray</a></li><li><a href="global.html#isBool">isBool</a></li><li><a href="global.html#isDate">isDate</a></li><li><a href="global.html#isFn">isFn</a></li><li><a href="global.html#isIOS">isIOS</a></li><li><a href="global.html#isiPad">isiPad</a></li><li><a href="global.html#isMap">isMap</a></li><li><a href="global.html#isNaN">isNaN</a></li><li><a href="global.html#isNull">isNull</a></li><li><a href="global.html#isNumber">isNumber</a></li><li><a href="global.html#isObj">isObj</a></li><li><a href="global.html#isPC">isPC</a></li><li><a href="global.html#isPrimitive">isPrimitive</a></li><li><a href="global.html#isPromise">isPromise</a></li><li><a href="global.html#isRegExp">isRegExp</a></li><li><a href="global.html#isSet">isSet</a></li><li><a href="global.html#isString">isString</a></li><li><a href="global.html#isSymbol">isSymbol</a></li><li><a href="global.html#isUndefined">isUndefined</a></li><li><a href="global.html#isWPhone">isWPhone</a></li><li><a href="global.html#ltrim">ltrim</a></li><li><a href="global.html#noop">noop</a></li><li><a href="global.html#random">random</a></li><li><a href="global.html#remove">remove</a></li><li><a href="global.html#reverse">reverse</a></li><li><a href="global.html#rtrim">rtrim</a></li><li><a href="global.html#throttle">throttle</a></li><li><a href="global.html#toFirstLower">toFirstLower</a></li><li><a href="global.html#toFirstUpper">toFirstUpper</a></li><li><a href="global.html#toKeys">toKeys</a></li><li><a href="global.html#toLowerCase">toLowerCase</a></li><li><a href="global.html#toParam">toParam</a></li><li><a href="global.html#toQuery">toQuery</a></li><li><a href="global.html#toUpperCase">toUpperCase</a></li><li><a href="global.html#toValues">toValues</a></li><li><a href="global.html#trim">trim</a></li><li><a href="global.html#typeOf">typeOf</a></li><li><a href="global.html#unique">unique</a></li><li><a href="global.html#uniqueToArray">uniqueToArray</a></li><li><a href="global.html#uniqueToNumber">uniqueToNumber</a></li><li><a href="global.html#uniqueToSizzArray">uniqueToSizzArray</a></li><li><a href="global.html#uniqueToSttring">uniqueToSttring</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.6</a> on Wed Dec 16 2020 10:48:43 GMT+0800 (GMT+08:00)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>