How to realize that there are only numbers and text in the data and remove other symbols

This can be done with regular expressions

const inputString = "用户【19806552283】[123]特殊字符$%^&*";
const cleanedString = inputString.replace(/[^a-zA-Z0-9\u4e00-\u9fa5]/g, '');

console.log(cleanedString); // 输出: "用户19806552283123特殊字符"

The above code uses a regular expression/[^a-zA-Z0-9\u4e00-\u9fa5]/g, which matches all characters except letters (upper and lower case), numbers and Chinese characters (including Chinese characters), and uses < The /span>, and you end up with a string with these special symbols removed. replace method replaces them with the empty string''

This regular expression[a-zA-Z0-9\u4e00-\u9fa5] matches letters, numbers and Chinese characters, ^ means negation within square brackets, so [^a-zA-Z0-9\u4e00-\u9fa5] matches all characters except these characters.

You can adjust the regular expression to accommodate different character sets as needed. In Vue.js, integrate this code into your component to handle strings when needed.

Guess you like

Origin blog.csdn.net/weixin_53818172/article/details/132473873