:page_facing_up:我收藏的、开发中用过的正则表达式,欢迎补充
可视化编辑测试工具:https://regexper.com/
^[1-9]\d{3}-([1-9]|1[0-2])-([1-9]|[1-2]\d|3[01])$
^.*?\.(html|css|jpg)$
^(?!\d{6,8}$)(?! )(?=.*[a-z])(?=.*[0-9])[a-zA-Z0-9_]{6,16}$
^(?!\d{6,8}$)(?! )(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])[a-zA-Z0-9_]{6,16}$
^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,}$
^[a-zA-Z]{1}[-_a-zA-Z0-9]{5,19}$
[1-9][0-9]{4,}
\d{3}-\d{8}|\d{4}-\{7,8}
^[+]{0,1}(d){1,3}[ ]?([-]?((d)|[ ]){1,12})+$
^1[34578]\d{9}$
^[+]{0,1}(d){1,3}[ ]?([-]?((d)|[ ]){1,12})+$
^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X|x)$
[1-9]\d{5}(?!\d)
(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d).(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d).(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d).(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)
[a-zA-z]+://[^\s]*
[\w!#$%&'*+/=?^_
{|}~-]+(?:.[\w!#$%&'+/=?^_`{|}~-]+)@(?:\w?.)+\w?`^[0-9]*$
^\d{n}$
^\d{n,}$
^\d{m,n}$
^(0|[1-9][0-9]*)$
^[0-9]+(.[0-9]{2})?$
^[0-9]+(.[0-9]{1,3})?$
^\+?[1-9][0-9]*$
^\-[1-9][0-9]*$
^\d+$
^((-\d+)|(0+))$
^.{3}$
^[A-Za-z]+$
^[A-Z]+$
^[a-z]+$
^[A-Za-z0-9]+$
^\w+$
^[a-zA-Z]\w{5,17}$
正确格式为:以字母开头,长度在6-18之间,只能包含字符、数字和下划线。 ^%&',;=?$\"
等字符:[^%&',;=?$\x22]+
^[\u4e00-\u9fa5],{0,}$
^\w+[-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$
^http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$ ;^[a-zA-z]+://(w+(-w+)*)(.(w+(-w+)*))*(?S*)?$
^(\(\d{3,4}\)|\d{3,4}-)?\d{7,8}$
:--正确格式为:XXXX-XXXXXXX,XXXX-XXXXXXXX,XXX-XXXXXXX,XXX-XXXXXXXX,XXXXXXX,XXXXXXXX。 ^\d{15}|\d{}18$
^(0?[1-9]|1[0-2])$
正确格式为:“01”-“09”和“1”“12” ^((0?[1-9])|((1|2)[0-9])|30|31)$
正确格式为:01、09和1、31。 ^-?\d+$
^\d+(\.\d+)?$
^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$
^((-\d+(\.\d+)?)|(0+(\.0+)?))$
^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$
^(-?\d+)(\.\d+)?$
*手机号码中间四位用代替**
function encryptPhone(val){
if(!val) return;
return val.replace(/^(\d{3})(\d{4})(\d+)/, '$1****$3')
}
encryptPhone('13173786224'); // 131****6224
格式化金额
var money = 1003450.89;
console.log(money.toString().replace(/(?=\B(?:\d{3})+\b)(\d{3}(?:\.\d+$)?)/g,',$1'));
// 1,003,450.89
JS替换字符串中的空格
var reg = /([^\s])\s+([^\s\b])/g;
var str = " 中国 北京 朝阳区 df ";
str = str.replace(reg, "$1%$2")
*不允许输入如下字符: (像 !@#$%^& 等)**
var userName = $("#userRegistName").val();
var first = userName.charCodeAt(0);
function CheckUserNameFormat(){
if ((first>=65 && first <= 90)||(first>=97 && first <=122)){
var pattern =/^[A-Za-z0-9_]+$/; //首字母必须是A-Z或者a-z
if(pattern.test(userName)){
......
}
}
匹配中文字符:[\u4e00-\u9fa5]
Copyright© 2013-2020
All Rights Reserved 京ICP备2023019179号-8