Home > Web Front-end > JS Tutorial > Introduction to JavaScript methods to determine whether the input string contains special symbols or expressions

Introduction to JavaScript methods to determine whether the input string contains special symbols or expressions

巴扎黑
Release: 2017-08-18 10:25:01
Original
2641 people have browsed it

This article mainly introduces the JavaScript code to determine whether the input string contains special characters and expressions. The judgment is made through the if statement of the js code, combined with the scenario developed by oneself. For the specific operation steps, you can check the detailed explanation below. Interested friends can refer to it.

The code is as follows:


reg = /[~#^$@%&!?%*]/gi;
if (reg.test(postdata.Name.trim())) {
alert("姓名不能含有特殊字符");
} else {
if (isEmojiCharacter(postdata.Name.trim())) {
alert("姓名不能含有表情");
} else {
//自己的代码
}
}
function isEmojiCharacter(substring) {
for (var i = 0; i < substring.length; i++) {
var hs = substring.charCodeAt(i);
if (0xd800 <= hs && hs <= 0xdbff) {
if (substring.length > 1) {
var ls = substring.charCodeAt(i + 1);
var uc = ((hs - 0xd800) * 0x400) + (ls - 0xdc00) + 0x10000;
if (0x1d000 <= uc && uc <= 0x1f77f) {
return true;
}
}
} else if (substring.length > 1) {
var ls = substring.charCodeAt(i + 1);
if (ls == 0x20e3) {
return true;
}
} else {
if (0x2100 <= hs && hs <= 0x27ff) {
return true;
} else if (0x2B05 <= hs && hs <= 0x2b07) {
return true;
} else if (0x2934 <= hs && hs <= 0x2935) {
return true;
} else if (0x3297 <= hs && hs <= 0x3299) {
return true;
} else if (hs == 0xa9 || hs == 0xae || hs == 0x303d || hs == 0x3030
|| hs == 0x2b55 || hs == 0x2b1c || hs == 0x2b1b
|| hs == 0x2b50) {
return true;
}
}
}
}
Copy after login

The above is the detailed content of Introduction to JavaScript methods to determine whether the input string contains special symbols or expressions. 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