Template
1
0
mirror of https://github.com/un-pany/v3-admin-vite.git synced 2025-04-21 11:29:20 +08:00

style: validate.ts

This commit is contained in:
pany 2022-08-22 10:17:28 +08:00
parent 45e999e15d
commit 402787bfae

View File

@ -1,4 +1,7 @@
export const isExternal = (path: string) => /^(https?:|mailto:|tel:)/.test(path)
export const isExternal = (path: string) => {
const reg = /^(https?:|mailto:|tel:)/
return reg.test(path)
}
export const isArray = (arg: any) => {
if (typeof Array.isArray === "undefined") {
@ -7,6 +10,13 @@ export const isArray = (arg: any) => {
return Array.isArray(arg)
}
export function isString(str: any) {
if (typeof str === "string" || str instanceof String) {
return true
}
return false
}
export const isValidURL = (url: string) => {
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.,?'\\+&%$#=~_-]+))*$/