?? tools.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;
}
//將HTML編碼轉換為實際對應的字符,得到真正的字符串
function getRealString(s){
s=replaceString(s,"<","<");
s=replaceString(s,">",">");
s=replaceString(s,"&","&");
s=replaceString(s,""","\"");
return s;
}
//to open a new window without status
function openwin(URL,winName,leftMargin,topMargin,winWidth,winHeight){
window.open(URL,winName,"left=" + leftMargin + " top=" + topMargin + " width=" + winWidth + ", height=" + winHeight + " menu=yes status=yes resizable=no scrollbars=yes");
}
//判斷是否是正整數
function isInteger(inputVal){
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"){
return false;
}
}
return true;
}
//判斷是否是正整數,加提示
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;
}
//判斷EAMIL是否合法
function check_email(address) {
var address=address;
if ((address == "") || (address.indexOf ('@') == -1) || (address.indexOf ('.') == -1))
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 emailVerify(objText,blnEmpty,intLength,strName ){
//校驗郵件錄入的有效性,有效返回true,無效返回false
var strText=objText.value;
if(strText=="" && blnEmpty==false){
alert("‘" + strName + "’不能為空!");
objText.focus();
return false;
}
if( strText.length > intLength){
alert("‘" + strName + "’不能超過 " + intLength + " 個字符,請更正!");
objText.select();
return false;
}
if ((strText == "") || (strText.indexOf ('@') == -1) || (strText.indexOf ('.') == -1)){
alert("‘" + strName + "’的格式不正確!");
objText.select();
return false;
}
return true;
}
function teleVerify(objText,blnEmpty,intLength,strName ){
//校驗電話號碼錄入的有效性,有效返回true,無效返回false
var strText=objText.value;
if(strText=="" && blnEmpty==false){
alert("‘" + strName + "’不能為空!");
objText.focus();
return false;
}
if( strText.length > intLength){
alert("‘" + strName + "’不能超過 " + intLength + " 個字符,請更正!");
objText.select();
return false;
}
var i;
for(i=0;i<strText.length;i++){
if((strText.charCodeAt(i)<48 || strText.charCodeAt(i)>57) && strText.charCodeAt(i)!=45){
alert("‘" + strName + "’只能填寫數字和連字符‘-’");
objText.select();
return false;
}
}
return true;
}
function telVerify(objText,intLength,strName ){
//校驗電話號碼錄入的有效性,有效返回true,無效返回false
var strText=Trim(objText.value);
if( strText.length > intLength){
alert("欄目‘"+strName+"’不能超過 "+intLength+" 個字符,請更正。");
objText.select();
return false;
}
var i;
for(i=0;i<strText.length;i++){
if((strText.charCodeAt(i)<48 || strText.charCodeAt(i)>57) && strText.charCodeAt(i)!=45){
alert("欄目‘"+strName+"’只能填寫數字和連字符‘-’");
objText.select();
return false;
}
}
return true;
}
function textVerify(objText,blnEmpty,intLength,strName) {
//校驗文本錄入的有效性,有效返回true,無效返回false
//objText為待校驗的頁面表單對象;blnEmpty表示此文本是否可為空,true表示可為空,false表示不可為空;
//intLength最大字節長度;strName校驗的對象欄目的名稱
var strText=objText.value;
var newText=trim(strText);
objText.value=newText;
if(newText=="" && blnEmpty==false) {
alert("‘" + strName + "’不能為空!");
if(objText.type!="hidden") {
objText.focus();
}
return false;
}
if(calculateStrLen(strText) > intLength) {
alert("‘" + strName + "’超過了指定的長度(" + intLength + "字符),請更正!");
if(objText.type!="hidden") {
objText.focus();
}
return false;
}
return true;
}
function charVerify(objText,blnEmpty,intLength,strName ){
//校驗純字母文本錄入的有效性,有效返回true,無效返回false
var strText=Trim(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=Trim(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=Trim(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=Trim(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;
}
/*
trim the blank space both head and tail.
@param str input string
@return string without blank space head and tail
*/
function trim(str){
var regExp = /[^\s]+(\s+[^\s]+)*/;
if(str == null)
return str;
var matchs = str.match(regExp);
if(matchs != null)
return matchs[0];
return "";
}
function dateOrderVerify(objStart,objEnd,blnEmpty,strStartName,strEndName ){
//校驗關聯日期的有效性,有效返回true,無效返回false
var strStart=objStart.value;
var strEnd=objEnd.value;
if(blnEmpty){
if(strStart=="" || strEnd==""){
return true;
}
}else{
if(strStart==""){
alert(strStartName + "不能為空!");
objStart.focus();
return false;
}
if(strEnd==""){
alert("‘" + strEndName + "’不能為空!");
objEnd.focus();
return false;
}
}
var intStart=(strStart.substring(0,4))*10000 + (strStart.substring(5,7))*100 + (strStart.substring(8,10));
var intEnd=(strEnd.substring(0,4))*10000 + (strEnd.substring(5,7))*100 + (strEnd.substring(8,10));
if(intStart>intEnd){
alert("‘" + strStartName + "’指定的日期不能比‘" + strEndName + "’指定的日期晚!");
objStart.focus();
return false;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -