Copy Code code as follows:
Match Chinese digit letter underline
var checkinput = function (str) {
var pattern =var pattern =/^[\w\u4e00-\u9fa5]+$/gi;
if (Pattern.test (c))
{
return false;
}
return true;
}
1.js filter special characters with regular expressions to verify that all input fields contain special symbols
Copy Code code as follows:
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 that all input fields contain special symbols
Copy Code code as follows:
/**
* Verify that all input fields contain special symbols
* The symbols to be filtered are written to the regular expression, noting that some symbols are to be escaped with ' \ '.
* Test Example:
* IF (Checkalltextvalid (Document.forms[0]))
* Alert ("All text boxes in the form pass the checksum!") ");
*/
function Checkalltextvalid (form) {
Record the number of text boxes that do not contain quotes
var resulttag = 0;
Record the number of all text boxes
var flag = 0;
for (var i = 0; i < form.elements.length; i++) {
if (Form.elements[i].type = = "Text") {
Flag = flag + 1;
Here to fill in the special symbols to be filtered
Note: Modify the ### #处的字符, other parts are not allowed to modify.
if (/^[^####]*$/.test (Form.elements[i].value))
if (/^[^\| "' <>]*$/.test (Form.elements[i].value))
Resulttag = Resulttag + 1;
Else
Form.elements[i].select ();
}
}
/**
* If a text box with quotes is equal to the value of all text boxes, the checksum passes
*/
if (Resulttag = = flag)
return true;
else {
Alert ("text box cannot contain \ n \ nthe 1 single quotes: ' \ n 2 double quotes: \" \ n 3 vertical bars: | \ n 4 SHARP horn: < > \ n) Please check the input! ");
return false;
}
}