Home > Web Front-end > JS Tutorial > body text

js regular verification special characters

不言
Release: 2018-04-26 14:37:01
Original
2229 people have browsed it

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

方案二

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; 
}
Copy after login

相关推荐: 

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template