⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 checkinpututil.js

📁 整理和编写的java script常用方法
💻 JS
📖 第 1 页 / 共 2 页
字号:
/*-------------- function index --------------trim       function:                                        trim() lTrim() rTrim()realLength function                                         realLength()isEmpty    function:                                        isEmpty()isNotEmpty function:                                        isNotEmpty()check a string is integer:                                  checkIsInteger(str)check a string is integer and not less the other value:     checkIntegerMinValue(str,val)check a string is integer and not bigger the other value:   checkIntegerMaxValue(str,val) check a string is not negative integer:             		isNotNegativeInteger(str)check a string is double:            						checkIsDouble(str) check a string is double and not less the other value:      checkDoubleMinValue(str,val)check a string is double and not bigger the other value:    checkDoubleMaxValue(str,val)check a string is not negative double:            			isNotNegativeDouble(str)check a string is date:           							checkIsValidDate(str)compare two date:              						 		checkDateEarlier(strStart,strEnd)check a string is email:         							checkEmail(str)check a string is URL:         							    checkUrl(str)check a string is IP:         							    checkIp(str)check a string is chinese:             						checkIsChinese(str)calculate string length,a chinese is two char:   			realLength()clear Form Input                                            clearFormInput()-------------- function index --------------*//********************************** Trim **************************************//*** remove space* trim:remove both side space lTrim:remove left side space rTrim: remove right side space* guide:*     var str = " hello ";*     str = str.trim();*/String.prototype.trim = function () {	return this.replace(/(^[\s]*)|([\s]*$)/g, "");};String.prototype.lTrim = function () {	return this.replace(/(^[\s]*)/g, "");};String.prototype.rTrim = function () {	return this.replace(/([\s]*$)/g, "");};/*** calculate the string length,chinese is two char*/String.prototype.realLength = function () {	return this.replace(/[^\x00-\xff]/g, "**").length;};/*--------------------------------- Trim --------------------------------------*//********************************** Empty **************************************//***check the string is  empty*return:*if the string is empty,pass check,  return true*if the string is not empty,         return false               */String.prototype.isEmpty = function () {	if (this.trim() == "") {		return true;	} else {		return false;	}};/***check the string is not empty*return:*if the string is not empty,pass check,  return true*if the string is empty,                 return false               */String.prototype.isNotEmpty = function () {	if (this.trim() == "") {		return false;	} else {		return true;	}};/*--------------------------------- Empty --------------------------------------*//********************************** Undefined **************************************//***check the string is defined*return:*if the string is defined, pass check,  return true*if the string is undefined,            return false               */function checkIsDefined(element) {	if (element == undefined) {		return false;	} else {		return true;	}}/*--------------------------------- Undefined --------------------------------------*//********************************** Integer *************************************//***check the string is Integer*return:*if the string is null, could not pass chesk,          return false*if the string is not Integer,pass check,              return true*if the string is Integer,                             return false               */function checkIsInteger(str) {	if (str == "") {		return false;	}	if (/^(\-?)(\d+)$/.test(str)) {		return true;	} else {		return false;	}}/***check the str is Integer and it bigger than the specify val*return:*if the string is null, could not pass chesk,                                return false*if the string is Integer and it bigger than the specify val ,pass check,      return true*else 												                         return false               */function checkIntegerMinValue(str, val) {	if (str == "") {		return false;	}	if (typeof (val) != "string") {		val = val + "";	}	if (checkIsInteger(str) == true) {		if (parseInt(str, 10) >= parseInt(val, 10)) {			return true;		} else {			return false;		}	} else {		return false;	}}/***check the str is Integer and it less than the specify val*return:*if the string is null, could not pass chesk,                                return false*if the string is Integer and it less than the specify val ,pass check,      return true*else 												                         return false               */function checkIntegerMaxValue(str, val) {	if (str == "") {		return false;	}	if (typeof (val) != "string") {		val = val + "";	}	if (checkIsInteger(str) == true) {		if (parseInt(str, 10) <= parseInt(val, 10)) {			return true;		} else {			return false;		}	} else {		return false;	}}/***check the string is not a negative Integer*return:*if the string is null, definition could not pass chesk,    return false*if the string is is not a negative Integer, pass check,    return true*else														return false					*/function isNotNegativeInteger(str) {	if (str == "") {		return false;	}	if (checkIsInteger(str) == true) {		if (parseInt(str, 10) < 0) {			return false;		} else {			return true;		}	} else {		return false;	}}/***check the string is not a negative Integer*return:*if the string is null, definition could not pass chesk,    return false*if the string is is not a negative Integer, pass check,    return true*else														return false					*/function isNotNegativeMaxInteger(str,val) {	if (str == "") {		return false;	}	if (checkIsInteger(str) == true) {		var inValue = parseInt(str, 10);		if (inValue >= 0 && inValue <= parseInt(val, 10)) {			return true;		} else{			return false;		}	} else {		return false;	}}/**check the string is Natural Number*/function checkNaturalNum(str){  return /^[1-9]\d*$/g.test(str);}/***cast the string to integer*return:*if the string is null or undefined,                        return 0*if the string is a Integer,							    return value*else														return 0					*/function changeStrIntoInteger(str){	var numStr = str.trim();	if(numStr=="" || numStr=="undefined")		return 0;	if(checkIsInteger(numStr)){	    return parseInt(numStr, 10);	 }	 else return 0;	        }/*--------------------------------- Integer --------------------------------------*//********************************** Double ****************************************//***check the string is Double*return:*if the string is null, could not pass chesk,          return false*if the string is not Double,pass check,               return true*if the string is Double,                              return false               */function checkIsDouble(str) {	if (str == "") {		return true;	}	if (str.indexOf(".") == -1) {		if (checkIsInteger(str) == true) {			return true;		} else {			return false;		}	} else {		if (/^(\-?)(\d+)(.{1})(\d+)$/g.test(str)) {			return true;		} else {			return false;		}	}}/***check the str is Double and it bigger than the specify val*return:*if the string is null, could not pass chesk,                                return false*if the string is Double and it bigger than the specify val ,pass check,       return true*else 												                         return false               */function checkDoubleMinValue(str, val) {	if (str == "") {		return true;	}	if (typeof (val) != "string") {		val = val + "";	}	if (checkIsDouble(str) == true) {		if (parseFloat(str) >= parseFloat(val)) {			return true;		} else {			return false;		}	} else {		return false;	}}/***check the str is Double and it less than the specify val*return:*if the string is null, could not pass chesk,                                return false*if the string is Double and it less than the specify val ,pass check,       return true*else 												                         return false               */function checkDoubleMaxValue(str, val) {	if (str == "") {		return true;	}	if (typeof (val) != "string") {		val = val + "";	}	if (checkIsDouble(str) == true) {		if (parseFloat(str) <= parseFloat(val)) {			return true;		} else {			return false;		}	} else {		return false;	}}/***check the string is not a negative double*return:*if the string is null, definition could not pass chesk,    return false*if the string is is not a negative double, pass check,     return true*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -