1. function IsURL (str_url) {
  2. var strRegex = '^((https|http|ftp|rtsp|mms)?://)'
  3. + '?(([0-9a-z_!~*\'().&=+$%-]+: )?[0-9a-z_!~*\'().&=+$%-]+@)?' //ftp的user@
  4. + '(([0-9]{1,3}.){3}[0-9]{1,3}' // IP形式的URL- 199.194.52.184
  5. + '|' // 允许IP和DOMAIN(域名)
  6. + '([0-9a-z_!~*\'()-]+.)*' // 域名- www.
  7. + '([0-9a-z][0-9a-z-]{0,61})?[0-9a-z].' // 二级域名
  8. + '[a-z]{2,6})' // first level domain- .com or .museum
  9. + '(:[0-9]{1,4})?' // 端口- :80
  10. + '((/?)|' // a slash isn't required if there is no file name
  11. + '(/[0-9a-z_!~*\'().;?:@&=+$,%#-]+)+/?)$';
  12. var re=new RegExp(strRegex);
  13. if (re.test(str_url)) {
  14. return (true);
  15. } else {
  16. return (false);
  17. }
  18. }
  1. function checkUrl(url){
  2. if(url!=""){
  3. var reg=/(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/;
  4. if(!reg.test(url)){
  5. alert("小可爱,网址不正确哦");
  6. }
  7. }
  8. }

ts类型覆盖

  1. # 创建一个辅助类型:
  2. type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
  3. # 用法:
  4. type HexColorLine = Overwrite<Line, { color: number }>