📄 verifyobj.js
字号:
<!--
//to replace all string1 with string2 in a fixed string.
function replaceString(s,s1,s2){
if(s.indexOf(s1)>=0){
s=s.substring(0,s.indexOf(s1))+s2+s.substring(s.indexOf(s1)+s1.length);
s=replaceString(s,s1,s2);
}
return s;
}
//判断是否是正整数,加提示
function isInteger(inputVal, strName){
inputStr=inputVal.toString();
for(var i=0;i<inputStr.length;i++) {
var oneChar=inputStr.charAt(i);
// if(i==0&&oneChar=="0")
// return false;
if(oneChar<"0"||oneChar>"9"){
alert("栏目‘"+strName+"’只能填写大于0的整数");
return false;
}
}
return true;
}
//判断是否是空字符串或空格字符串
function isVoidStr(inputVal){
if(inputVal.length==0){
return true;
} else {
var oneChar="";
for(var i=0;i<inputVal.length;i++) {
oneChar=inputVal.charAt(i);
if(oneChar!=' ') {
return false;
}
}
}
return true;
}
//得到字符串的字节长度
function calculateStrLen(str){
var i,intLen=0;
for(i=0;i<str.length;i++){
if (str.charCodeAt(i)>126){
intLen++;
}
intLen++;
}
return intLen;
}
function charVerify(objText,blnEmpty,intLength,strName ){
//校验纯字母文本录入的有效性,有效返回true,无效返回false
var strText=objText.value;
if(strText=="" && blnEmpty==false){
alert("栏目‘"+strName+"’不能为空。");
objText.focus();
return false;
}
var i;
for(i=0;i<strText.length;i++){
if(strText.charCodeAt(i)!=32){
if(strText.charCodeAt(i)<65 || ( strText.charCodeAt(i)>90 && strText.charCodeAt(i)<97 ) || strText.charCodeAt(i)>122 ){
alert("栏目‘"+strName+"’只能填写字母。");
objText.select();
return false;
}
}
}
if(strText.length > intLength){
alert("栏目‘"+strName+"’不能超过 "+intLength+" 个字符,请更正。");
objText.select();
return false;
}
return true;
}
function char_numVerify(objText,blnEmpty,intLength,strName ){
//校验纯字母和数字文本录入的有效性,有效返回true,无效返回false
var strText=objText.value;
if(strText=="" && blnEmpty==false){
alert("栏目‘"+strName+"’不能为空。");
objText.focus();
return false;
}
var i;
for(i=0;i<strText.length;i++){
if(strText.charCodeAt(i)!=32){
if(strText.charCodeAt(i)<48 || ( strText.charCodeAt(i)>57 && strText.charCodeAt(i)<65 ) || ( strText.charCodeAt(i)>90 && strText.charCodeAt(i)<97 ) || strText.charCodeAt(i)>122 ){
alert("栏目‘"+strName+"’只能填写字母和数字。");
objText.select();
return false;
}
}
}
if(strText.length > intLength){
alert("栏目‘"+strName+"’不能超过 "+intLength+" 个字符,请更正。");
objText.select();
return false;
}
return true;
}
function numberVerify(objText,blnEmpty,intLength,strName ){
//校验纯数字文本录入的有效性,有效返回true,无效返回false
var strText=objText.value;
if(strText=="" && blnEmpty==false){
alert("栏目‘"+strName+"’不能为空。");
objText.focus();
return false;
}
var i;
for(i=0;i<strText.length;i++){
if((strText.charCodeAt(i)<48 || strText.charCodeAt(i)>57)){
alert("栏目‘"+strName+"’只能填写数字。");
objText.select();
return false;
}
}
if(strText.length > intLength){
alert("栏目‘"+strName+"’不能超过 "+intLength+" 个字符,请更正。");
objText.select();
return false;
}
return true;
}
function positiveIntVerify(objText,blnEmpty,intLength,strName){
//校验正整数录入的有效性,有效返回true,无效返回false
var strText=objText.value;
if(strText=="" && blnEmpty==false){
alert("栏目‘"+strName+"’不能为空。");
objText.focus();
return false;
}
var i;
for(i=0;i<strText.length;i++){
if((strText.charCodeAt(0)==48 || strText.charCodeAt(i)<48 || strText.charCodeAt(i)>57)){
alert("栏目‘"+strName+"’只能填写正整数。");
objText.select();
return false;
}
}
if(strText.length > intLength){
alert("栏目‘"+strName+"’不能超过 "+intLength+" 个字符,请更正。");
objText.select();
return false;
}
return true;
}
function intVerify(objText,blnEmpty,intLength,strName ){
//校验整数文本录入的有效性,有效返回true,无效返回false
var strText=objText.value;
if(strText=="" && blnEmpty==false){
alert("栏目‘"+strName+"’不能为空。");
objText.focus();
return false;
}
var i;
for(i=0;i<strText.length;i++){
if((strText.charCodeAt(i)<48 || strText.charCodeAt(i)>57)){
alert("栏目‘"+strName+"’只能填写整数。");
objText.select();
return false;
}
}
if(strText.length > intLength){
alert("栏目‘"+strName+"’不能超过 "+intLength+" 个字符,请更正。");
objText.select();
return false;
}
return true;
}
function doubleVerify(objText,blnEmpty,totalLen,decimalLen,strName ){
//校验带小数数字文本录入的有效性,有效返回true,无效返回false
var strText=objText.value;
if(strText=="" && blnEmpty==false){
alert("栏目‘"+strName+"’不能为空。");
objText.focus();
return false;
}
var i;
for(i=0;i<strText.length;i++){
if((strText.charCodeAt(i)<48 || strText.charCodeAt(i)>57) && strText.charCodeAt(i)!=46&& strText.charCodeAt(i)!=69){
alert("栏目‘"+strName+"’只能填写数字。");
objText.select();
return false;
}
}
var point=strText.indexOf('.');
if( point==-1){
if(strText.length > totalLen-decimalLen){
alert("栏目‘"+strName+"’不能超过 "+intLength+" 个字符,请更正。");
objText.select();
return false;
}
}else{
if(point > totalLen-decimalLen){
alert("栏目‘"+strName+"’不能超过 "+intLength+" 个字符,请更正。");
objText.select();
return false;
}
}
return true;
}
function textVerify(objText,blnEmpty,intLength,strName ){
//校验文本录入的有效性,有效返回true,无效返回false
//objText为待校验的页面表单对象;blnEmpty表示此文本是否可为空,true表示可为空,false表示不可为空;
//intLength最大字节长度;strName校验的对象栏目的名称
var strText=objText.value;
if(strText=="" && blnEmpty==false){
alert("栏目‘"+strName+"’不能为空。");
objText.focus();
return false;
}
if(calculateStrLen(strText) > intLength){
alert("栏目‘"+strName+"’不能超过 "+intLength+" 个字符,请更正。");
objText.select();
return false;
}
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -