常用正则表达式

1.手机号验证

let regex = /^1[34578]\d{9}$/g;

2.用户名验证(4到16位(字母,数字,下划线,减号))

let regex = /^[a-zA-Z\$][a-zA-Z0-9_\$]{4,16}$/;

3.qq号验证(5-11位)

let regex = /^[1-9][0-9]{4,10}$/g;

4.日期验证(yyyy-mm-dd)

let regex = /^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/;

5.十六进制颜色

let regex = /#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})/g;

6.身份证验证

let regex = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;

7.email验证

let regex = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

8.数字验证

//正数正则
let posPattern = /^\d*\.?\d+$/;
//负数正则
let negPattern = /^-\d*\.?\d+$/;
//数字正则
let numPattern = /^-?\d*\.?\d+$/;

9.车牌号验证

let cPattern = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$/;

10. url验证

let urlP= /^((https?|ftp|file):\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/;

相关推荐