提交 | 用户 | 时间
|
e57a89
|
1 |
/** |
懒 |
2 |
* @param {string} path |
|
3 |
* @returns {Boolean} |
|
4 |
*/ |
|
5 |
export function isExternal(path) { |
|
6 |
return /^(https?:|mailto:|tel:)/.test(path) |
|
7 |
} |
|
8 |
|
|
9 |
/** |
|
10 |
* @param {string} str |
|
11 |
* @returns {Boolean} |
|
12 |
*/ |
|
13 |
export function validUsername(str) { |
|
14 |
const valid_map = ['admin', 'editor'] |
|
15 |
return valid_map.indexOf(str.trim()) >= 0 |
|
16 |
} |
|
17 |
|
|
18 |
/** |
|
19 |
* @param {string} url |
|
20 |
* @returns {Boolean} |
|
21 |
*/ |
|
22 |
export function validURL(url) { |
|
23 |
const reg = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/ |
|
24 |
return reg.test(url) |
|
25 |
} |
|
26 |
|
|
27 |
/** |
|
28 |
* @param {string} str |
|
29 |
* @returns {Boolean} |
|
30 |
*/ |
|
31 |
export function validLowerCase(str) { |
|
32 |
const reg = /^[a-z]+$/ |
|
33 |
return reg.test(str) |
|
34 |
} |
|
35 |
|
|
36 |
/** |
|
37 |
* @param {string} str |
|
38 |
* @returns {Boolean} |
|
39 |
*/ |
|
40 |
export function validUpperCase(str) { |
|
41 |
const reg = /^[A-Z]+$/ |
|
42 |
return reg.test(str) |
|
43 |
} |
|
44 |
|
|
45 |
/** |
|
46 |
* @param {string} str |
|
47 |
* @returns {Boolean} |
|
48 |
*/ |
|
49 |
export function validAlphabets(str) { |
|
50 |
const reg = /^[A-Za-z]+$/ |
|
51 |
return reg.test(str) |
|
52 |
} |
|
53 |
|
|
54 |
/** |
|
55 |
* @param {string} email |
|
56 |
* @returns {Boolean} |
|
57 |
*/ |
|
58 |
export function validEmail(email) { |
|
59 |
const reg = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ |
|
60 |
return reg.test(email) |
|
61 |
} |
|
62 |
|
|
63 |
/** |
|
64 |
* @param {string} str |
|
65 |
* @returns {Boolean} |
|
66 |
*/ |
|
67 |
export function isString(str) { |
|
68 |
return typeof str === 'string' || str instanceof String; |
|
69 |
} |
|
70 |
|
|
71 |
/** |
|
72 |
* @param {Array} arg |
|
73 |
* @returns {Boolean} |
|
74 |
*/ |
|
75 |
export function isArray(arg) { |
|
76 |
if (typeof Array.isArray === 'undefined') { |
|
77 |
return Object.prototype.toString.call(arg) === '[object Array]' |
|
78 |
} |
|
79 |
return Array.isArray(arg) |
|
80 |
} |