Skip to content

Commit

Permalink
feat: add url reg
Browse files Browse the repository at this point in the history
  • Loading branch information
fupengl committed Jun 10, 2021
1 parent 91f585e commit 02f0e0a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/regex_constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,18 @@ export const REG_URI_WITH_PORT = /^((ht|f)tps?:\/\/)?[\w-]+(\.[\w-]+)+:\d{1,5}\/

/**
* 网址(url,支持端口和"?+参数"和"#+参数)
* @note 没有协议也会校验通过
*/
// eslint-disable-next-line
export const REG_URI = /^(((ht|f)tps?):\/\/)?[\w-]+(\.[\w-]+)+([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?$/;
export const REG_URI_LOSE = /^(((ht|f)tps?):\/\/)?[\w-]+(\.[\w-]+)+([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?$/;

/**
* 网址校验,必须带有协议,或者相对协议
*/
export const REG_URI = new RegExp(
'^(?!mailto:)(?:(?:http|https|ftp)://|//)(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-*)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-*)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?$',
'i',
);

/**
* 子网掩码
Expand Down

0 comments on commit 02f0e0a

Please sign in to comment.