//Match Chinese digits, letters and underscores
var checkInput = function (str) {
var pattern = var pattern = /^[wu4e00-u9fa5] $/gi;
> }
}
return true;
}
1.js uses regular expressions to filter special characters and verify whether all input fields contain special symbols
function stripscript(s) {
var pattern = new RegExp("[`~! @#$^&*()=|{}':;',\[\].<>/?~! @#¥......&*()——|{}[]';:" "'.,,?]")
var rs = "";
for (var i = 0; i < s.length; i ) {
rs = rs s.substr(i, 1).replace(pattern, '');
}
return rs;
}
2. Verify whether all input fields contain special symbols
/**
* Verify whether all input fields contain special symbols
* Write the symbols to be filtered into the regular expression. Note that some symbols need to be escaped with ''.
* Test example:
* if(checkAllTextValid(document.forms[0]))
* alert("All text boxes in the form passed verification!");
*/
function checkAllTextValid(form) {
//Record the number of text boxes without quotation marks
var resultTag = 0;
//Record the number of all text text boxes
var flag = 0;
for (var i = 0; i < form.elements.length; i ) {
if (form.elements[i].type == "text") {
flag = flag 1;
//Fill in the required filter here Special symbols
’’ ’ ’ ’s ’ ’ s ’ ’ s ’ ’ s ’ ’ s ‐ ‐ ‐ ‐ ‐ ‐ ‐ i].value))
If (/^[^|"'<>]*$/.test(form.elements[i].value))
resultTag = resultTag 1;
else
form.elements[i].select();
}
}
/**
* If the text box containing quotes is equal to the value of all text boxes, the verification passes
*/
if (resultTag == flag )
return true;
else {
alert("The text box cannot contain nn 1 single quotes: ' n 2 double quotes: " n 3 vertical bars: | n 4 sharp angles: < > nnPlease check your input! ");
return false;
}
}