js正则表达式
三部曲
需求、迭代、实现
例子
身份证正则:const reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\dX|x)$)/
数字正则:const reg = /[0-9]/
英文正则:const reg = /^[a-z]+$/i
中文正则:const reg = /[\u4e00/\u9fa5]/gm
数字逗号正则:const reg = /^[\d,]*$/
英文特殊字符正则:const reg = /[`~!@#$%^&*()_<>?:"{},\\.\/;'[\]]/im
中文特殊字符正则:const reg = /[·!#¥(——):;“”‘’、,|《》。?【】[\]]/im
手机号正则:const reg = /^[1][3,4,5,7,8][0-9]{9}$/
电子邮件正则:const reg = /^([A-Za-z0-9_\-\.\u4e00-\u9fa5])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,8}$)/
url正则:const reg = /((http|ftp|https):\/\/)?[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/ig

浙公网安备 33010602011771号