图片链接地址
验证图片链接地址,图片格式
可按需增删,必须包含 http/https
。
语法
import { imgUrlReg } from 'warbler-js';
const result = imgUrlReg(value);
参数
value
(String) : 待验证字符串。
返回值
Boolean : 是否通过验证,true
通过验证, false
没有通过验证。
源码
const imgUrlReg = (value) => {
const reg = /^https?:\/\/(.+\/)+.+(\.(gif|png|jpg|jpeg|webp|svg|psd|bmp|tif))$/i;
return reg.test(value);
};
例子
import { imgUrlReg } from 'warbler-js';
const result1 = imgUrlReg('http://warbler.duwanyu.com/wc.png')
const result2 = imgUrlReg('https://warbler.duwanyu.com/wc.png')
const result3 = imgUrlReg('warbler.duwanyu.com/wc.png')
console.log(result1) // true
console.log(result2) // true
console.log(result3) // false