This article is mainly on the JS special character filter Sample code is introduced, the need for friends can come to the reference, hope to help everyone else
Code as follows://Match Chinese digit letter underscore var checkinput = function (str) { &NBS P var pattern =var pattern =/^[wu4e00-u9fa5]+$/gi; if (Pattern.test (c)) { &N Bsp return false; return true; } 1.js filter special characters with regular expressions to verify that all input fields contain special symbols The code is as follows: function Stripscript (s) { &nbs P 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 that all input fields contain special symbols code as follows:/** * Verify that all input fields contain special symbols * the symbols to be filtered are written to the regular expression, note that some symbols are used' Escaped. * Sample: * if (Checkalltextvalid (document.forms[0)) * alert ("All text boxes in the form pass the checksum!") "); */function Checkalltextvalid (form) { //record number of text boxes without quotes var resulttag = 0; // Record all text box quantity var flag = 0; for (var i = 0; i < form.elements.length i++) { if (Form.elements[i].type = = "Text" { flag = flag + 1; //fill in the filter Special symbols /Note: Modify ### #处的字符, other parts are not allowed to modify. //if (/^[^####]*$/.test (form.elements[i].value)) &NB Sp if (/^[^| "' <>]*$/.test (Form.elements[i].value)) Resulttag = Resulttag + 1; else form.elements[i].se Lect (); { } /** * If a text box with quotes is equal to the value of all text boxes, the checksum passes the &NB sp;*/ if (Resulttag = = flag) return true; Else { alert ("text box cannot contain nn 1 single quotes: ' N 2 double quotes:" N 3 Vertical bars: | N 4 Sharp Corner number: < > NN please check the input! "); return false; }}