/**
* Data verification framework. When an error occurs when checking for id fields is added, add a <span> element to the corresponding field to display the error message.
*
* @author wangzi6hao
* @version 2.1
* @description 2009-05-16
*/
var checkData = new function() {
var idExt="_wangzi6hao_Span";//Generate the id suffix of the span layer
/**
* Get Chinese and English characters long (2 characters in Chinese)
*
* @param {}
* str
* @return Character length
*/
= function(str) {
var p1 = new RegExp('%u..', 'g')
var p2 = new RegExp('%.', 'g')
return escape(str).replace(p1, '').replace(p2, '').length
}
/**
* Delete the corresponding id element
*/
= function(id) {
var idObject = (id);
if (idObject != null)
(idObject);
}
/**
* Error message after the corresponding id
*
* @param id: The id element that needs to display error message
* str: Display error message
*/
= function(id, str) {
(id + idExt);// If the span element exists, delete this element first
var spanNew = ("span");// Create span
= id + idExt;// Generate spanid
= "red";
((str));// Add content to the span
var inputId = (id);
(spanNew, );// Add span after adding elements to the need
}
/**
* @description Filters all space characters.
* @param str: The original string that needs to be removed from space
* @return Return a string with spaces removed
*/
= function(str) {
str += "";
while (((0) == ' ') || ((0) == '???')
|| (escape((0)) == '%u3000'))
str = (1, );
while ((( - 1) == ' ')
|| (( - 1) == '???')
|| (escape(( - 1)) == '%u3000'))
str = (0, - 1);
return str;
}
/**
* Filter the spaces in the beginning of the string\Spaces in the end of the string\Change multiple connected spaces in the middle of the text into a space
*
* @param {Object}
* inputString
*/
= function(inputString) {
if (typeof inputString != "string") {
return inputString;
}
var retValue = inputString;
var ch = (0, 1);
while (ch == " ") {
// Check the spaces at the beginning of the string
retValue = (1, );
ch = (0, 1);
}
ch = ( - 1, );
while (ch == " ") {
// Check the spaces in the end part of the string
retValue = (0, - 1);
ch = ( - 1, );
}
while ((" ") != -1) {
// Turn multiple connected spaces in the middle of the text into a space
retValue = (0, (" "))
+ ((" ") + 1,
);
}
return retValue;
}
/**
* Filter string, specify the filtering content. If the content is empty, the default filtering is '~!@#$%^&*()-+."
*
* @param {Object}
* str
* @param {Object}
* filterStr
*
* @return contains filtered content, returns True, otherwise returns false;
*/
= function(str, filterString) {
filterString = filterString == "" ? "'~!@#$%^&*()-+.\"" : filterString
var ch;
var i;
var temp;
var error = false;// Return True when containing illegal characters
for (i = 0; i <= ( - 1); i++) {
ch = (i);
temp = (ch);
if (temp != -1) {
error = true;
break;
}
}
return error;
}
= function(id, filterString) {
filterString = filterString == "" ? "'~!@#$%^&*()-+.\"" : filterString
var val = (id);
if ((, filterString)) {
();
var str = "cannot contain illegal characters" + filterString;
(id, str);
return false;
} else {
(id + idExt);
return true;
}
}
/**
* Check if it is a URL
*
* @param {}
* str_url
* @return {Boolean} true: It is a URL, false:<b>not</b> URL;
*/
= function(str_url) {// Verify url
var strRegex = "^((https|http|ftp|rtsp|mms)?://)"
+ "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" // user@ of ftp
+ "(([0-9]{1,3}\.){3}[0-9]{1,3}" // URL in IP form- 199.194.52.184
+ "|" // Allow IP and DOMAIN (domain)
+ "([0-9a-z_!~*'()-]+\.)*" // Domain name- www.
+ "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." // Secondary Domain Name
+ "[a-z]{2,6})" // first level domain- .com or .museum
+ "(:[0-9]{1,4})?" // Port- :80
+ "((/?)|" // a slash isn't required if there is no file name
+ "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$";
var re = new RegExp(strRegex);
return (str_url);
}
= function(id) {
var val = (id);
if (!()) {
();
var str = "The link does not conform to the format;";
(id, str);
return false;
} else {
(id + idExt);
return true;
}
}
/**
* Check if it is an email
*
* @param {}
* str
* @return {Boolean} true: Email, false:<b>not</b>email;
*/
= function(str) {
var re = /^([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
return (str);
}
= function(id) {
var val = (id);
if (!()) {
();
var str = "The email does not conform to the format;";
(id, str);
return false;
} else {
(id + idExt);
return true;
}
}
/**
* Check if it is a number
*
* @param {}
* str
* @return {Boolean} true: number, false:<b>not</b>number;
*/
= function(str) {
var re = /^[\d]+$/
return (str);
}
= function(id) {
var val = (id);
if (!()) {
();
var str = "must be a number;";
(id, str);
return false;
} else {
(id + idExt);
return true;
}
}
/**
* Check whether the value is within the given range, it is empty, and no check is done<br>
*
* @param {}
* str_num
* @param {}
* small value that should be greater than or equal to (if this value is empty, only check cannot be greater than the maximum value)
* @param {}
* big value that should be less than or equal to (if this value is empty, only check cannot be less than the minimum value)
*
* @return {Boolean} <b>Lower than the minimum value or greater than the maximum value</b>Number returns false otherwise returns true;
*/
= function(str_num, small, big) {
if (!(str_num)) // Check if it is a number
return false
if (small == "" && big == "")
throw str_num + "No maximum and minimum value number defined!";
if (small != "") {
if (str_num < small)
return false;
}
if (big != "") {
if (str_num > big)
return false;
}
return true;
}
= function(id, small, big) {
var val = (id);
if (!(, small, big)) {
();
var str = "";
if (small != "") {
str = "should be greater than or equal to " + small;
}
if (big != "") {
str += " should be less than or equal to " + big;
}
(id, str);
return false;
} else {
(id + idExt);
return true;
}
}
/**
* Check whether it is a qualified string (case insensitive)<br>
* is a string composed of a-z0-9_
*
* @param {}
* str Checked string
* @param {}
* idStr The field ID that the cursor is positioned<b>Only receive ID</b>
* @return {Boolean} <b>Not</b>"a-z0-9_" composition returns false, otherwise returns true;
*/
= function(str) {
var re = /^[_0-9a-zA-Z]*$/
return (str);
}
= function(id) {
var val = (id);
if (!()) {
();
var str = "is a string composed of a-z0-9_ (case insensitive);";
(id, str);
return false;
} else {
(id + idExt);
return true;
}
}
/**
* Check whether the two strings are equal
*
* @param {}
* str1 first string
* @param {}
* str2 The second string
* @return {Boolean} The string is not equal and returns false, otherwise it returns true;
*/
= function(str1, str2) {
return str1 == str2;
}
= function(id, id1) {
var val = (id);
var val1 = (id1);
if (!(, )) {
();
var str = "The content of the secondary input must be the same;";
(id, str);
return false;
} else {
(id + idExt);
return true;
}
}
/**
* Check whether the string is within the given length range (Chinese characters are calculated in 2 bytes), the characters are empty, no checking is done<br>
*
* @param {}
* str Checked character
* @param {}
* lessLen should be greater than or equal to the length
* @param {}
* moreLen should be less than or equal to the length
*
* @return {Boolean} <b>Lower than the minimum length or greater than the maximum length</b>Number returns false;
*/
= function(str, lessLen, moreLen) {
var strLen = (str);
if (lessLen != "") {
if (strLen < lessLen)
return false;
}
if (moreLen != "") {
if (strLen > moreLen)
return false;
}
if (lessLen == "" && moreLen == "")
throw "The maximum and minimum length is not defined!";
return true;
}
= function(id, lessLen, moreLen) {
var val = (id);
if (!(, lessLen, moreLen)) {
var str = "length";
if (lessLen != "")
str += "greater than or equal to " + lessLen + ";";
if (moreLen != "")
str += " should be less than or equal to " + moreLen;
();
(id, str);
return false;
} else {
(id + idExt);
return true;
}
}
/**
* Check whether the string is less than the given length range (Chinese characters are calculated in 2 bytes)<br>
*
* @param {}
* str string
* @param {}
* lessLen is less than or equal to length
*
* @return {Boolean} <b>Lower than the given length</b>Number returns false;
*/
= function(str, lessLen) {
return (str, lessLen, "");
}
= function(id, lessLen) {
var val = (id);
if (!(, lessLen)) {
var str = "Length greater than or equal to " + lessLen;
();
(id, str);
return false;
} else {
(id + idExt);
return true;
}
}
/**
* Check whether the string is larger than the given length range (Chinese characters are calculated in 2 bytes)<br>
*
* @param {}
* str string
* @param {}
* moreLen less than or equal to length
*
* @return {Boolean} <b>Greater than the given length</b>Number returns false;
*/
= function(str, moreLen) {
return (str, "", moreLen);
}
= function(id, moreLen) {
var val = (id);
if (!(, moreLen)) {
var str = "The length should be less than or equal to " + moreLen;
();
(id, str);
return false;
} else {
(id + idExt);
return true;
}
}
/**
* Check that the characters are not empty
*
* @param {}
* str
* @return {Boolean} <b>The character is empty</b> returns true, otherwise it is false;
*/
= function(str) {
return str == "";
}
= function(id) {
var val = (id);
if (()) {
var str = "Not allowed;";
();
(id, str);
return false;
} else {
(id + idExt);
return true;
}
}
}