fix: 参数配置值类型为字符串http判断

This commit is contained in:
TsMask
2023-12-25 20:55:59 +08:00
parent e79d054ceb
commit 864be2ba3b
2 changed files with 58 additions and 3 deletions

View File

@@ -28,7 +28,8 @@ export const regExpUserName = /^[a-zA-Z][a-z0-9A-Z]{4,}$/;
*
* 密码至少包含大小写字母、数字、特殊符号且不少于6位
*/
export const regExpPasswd = /^(?![A-Za-z0-9]+$)(?![a-z0-9\W]+$)(?![A-Za-z\W]+$)(?![A-Z0-9\W]+$)[a-zA-Z0-9\W]{6,}$/;
export const regExpPasswd =
/^(?![A-Za-z0-9]+$)(?![a-z0-9\W]+$)(?![A-Za-z\W]+$)(?![A-Z0-9\W]+$)[a-zA-Z0-9\W]{6,}$/;
/**
* 有效手机号格式
@@ -63,6 +64,44 @@ export function validHttp(link: string): boolean {
return regExpHttp.test(link);
}
/**
* 判断是否有效URL地址
* @param str 网络链接
* @returns true | false
*/
export function validURL(str: string) {
if (
str === '' ||
str.length >= 2083 ||
str.length <= 3 ||
str.startsWith('.')
) {
return false;
}
let strTemp = str;
if (str.includes(':') && !str.includes('://')) {
// support no indicated urlscheme but with colon for port number
// http:// is appended so url.Parse will succeed, strTemp used so it does not impact rxURL.MatchString
strTemp = 'http://' + str;
}
debugger;
try {
new URL(strTemp);
} catch (error) {
return false;
}
const u = new URL(strTemp);
if (u.host.startsWith('.')) {
return false;
}
if (u.host === '' && u.pathname !== '' && !u.pathname.includes('.')) {
return false;
}
// 正则表达式模式(rxURL)未提供,无法进行具体判断
return true;
}
/**
* 判断是否为有效手机号格式
* @param mobile 手机号字符串