图片链接地址

验证图片链接地址,图片格式 可按需增删,必须包含 http/https

语法

  1. import { imgUrlReg } from 'warbler-js';
  2. const result = imgUrlReg(value);

参数

  • value (String) : 待验证字符串。

返回值

Boolean : 是否通过验证,true 通过验证, false 没有通过验证。

源码

  1. const imgUrlReg = (value) => {
  2. const reg = /^https?:\/\/(.+\/)+.+(\.(gif|png|jpg|jpeg|webp|svg|psd|bmp|tif))$/i;
  3. return reg.test(value);
  4. };

例子

  1. import { imgUrlReg } from 'warbler-js';
  2. const result1 = imgUrlReg('http://warbler.duwanyu.com/wc.png')
  3. const result2 = imgUrlReg('https://warbler.duwanyu.com/wc.png')
  4. const result3 = imgUrlReg('warbler.duwanyu.com/wc.png')
  5. console.log(result1) // true
  6. console.log(result2) // true
  7. console.log(result3) // false