Home  >  Article  >  Web Front-end  >  js regular verification special characters

js regular verification special characters

不言
不言Original
2018-04-26 14:37:012226browse

本篇文章向大家分享的内容是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; 
}

相关推荐: 

JS正则表达式详解

JS正则表达式验证数字的实战归纳 

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn