头图

去除html标签

let str = "<p>这是一段通告</p>"
let text = str.replace(/<[^>]+>/g,"")
console.log(text); // 这是一段通告

http转https

const httpReg = (url) => {
    let regExp = /^http:\/\//;
    if (!regExp.test(url)) return false;
    return s.replace('http://', 'https://');
}

let url = 'http://www.gjtool.cn/pdfh5/git.pdf'
console.log(httpReg(url)); // https://www.gjtool.cn/pdfh5/git.pdf

手机号码

/** @desc 正则-手机号码 */
export const Phone = /^1[3-9]\d{9}$/

邮箱

/** @desc 正则-邮箱 */
export const Email = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/

6位数字验证码正则

/** @desc 正则-6位数字验证码正则 */
export const Code_6 = /^\d{6}$/

4位数字验证码正则

/** @desc 正则-4位数字验证码正则 */
export const Code_4 = /^\d{4}$/

16进颜色值

/** @desc 正则-16进颜色值 #333 #8c8c8c */
export const ColorRegex = /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/

只能是中文

/** @desc 正则-只能是中文 */
export const OnlyCh = /^[\u4e00-\u9fa5]+$/gi

只能是英文

/** @desc 正则-只能是英文 */
export const OnlyEn = /^[a-zA-Z]*$/

登录注册-密码 6-16位大小写字母、数字的js正则

/** @desc 登录注册-密码 6-16位大小写字母、数字的js正则 */
export const Password = /^[a-zA-Z0-9]{6,16}$/

座机号码

/** @desc 座机号码 */
export const Mobile = /^(((\d{3,4}-)?[0-9]{7,8})|(1(3|4|5|6|7|8|9)\d{9}))$/

身份证-可校验末尾X

let idCardRegex = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;

兔子先森
465 声望439 粉丝

致力于新技术的推广与优秀技术的普及。


« 上一篇
pdf测试链接