Home > Article > Web Front-end > js regular verification special characters
本篇文章向大家分享的内容是js正则验证特殊字符,有需要的朋友可以参考一下
l来源:https://www.cnblogs.com/summer7310/p/7159665.html
js正则验证特殊字符
var regEn = /[`~!@#$%^&*()_+<>?:"{},.\/;'[\]]/im, regCn = /[·!#¥(——):;“”‘、,|《。》?、【】[\]]/im;if(regEn.test(newName) || regCn.test(newName)) { alert("名称不能包含特殊字符."); return false; }
function checkName(val){ var reg = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“'。,、?]"); var rs = ""; for (var i = 0, l = val.length; i < val.length; i++) { rs = rs + val.substr(i, 1).replace(reg, ''); } return rs; }
相关推荐:
The above is the detailed content of js regular verification special characters. For more information, please follow other related articles on the PHP Chinese website!