﻿new RegExp()
"".regext
/*作者：赵虎
 *时间：2009-11-11
 *功能: 检测文本框字符越界
 */
//1欲检测的对像
//2欲检测的最大符长度
//3对错误的描述信息 对像ID
//4是否用对话框提示
function checkMaxChar(obj, len, desObj, showAlert, fn){


    if (obj.value.length > len) {
    
		obj.value = obj.value.substring(0, len);
        if (fn != undefined && fn != null) {
            fn(obj);
        }
        if (showAlert) {
            alert("请控制在 " + len + " 字符以内！多余字符系统自动截取");
        }
    }
    if (obj.value.length >= len) {
    
        $("#" + desObj).css("color", "#ff0000");
    }
    else {
        if (obj.value.length > len / 3 && obj.value.length < len / 1.5) {
        
            $("#" + desObj).css("color", "#ffaa55");
        }
        else {
            if (obj.value.length > len / 1.5) {
            
                $("#" + desObj).css("color", "red");
            }
            else {
            
                $("#" + desObj).css("color", "#000000");
            }
        }
    }
    $("#" + desObj).show();
    $("#" + desObj).text(obj.value.length + "/" + len);
}

//1欲检测的对像
//2欲检测的最大符长度
//3对错误的描述信息 对像ID
//4是否用对话框提示
    function checkshowMaxChar(obj, len, desObj, showAlert, fn){
    if (obj.value.length > len) {
    
		obj.value = obj.value.substring(0, len);
        $("#" + desObj).css("color", "#ff0000");
        if (fn != undefined && fn != null) {
            fn(obj);
        }
        if (showAlert) {
            alert("请控制在 " + len + " 字符以内！多余字符系统自动截取");
        }
    }
    else {
        $("#" + desObj).css("color", "#000000");
    }
        $("#" + desObj).html("还能输入<em>" + (len-obj.value.length) + "</em>字" );
}

function AutoMaxChar(object, len, span, isShowAlert){

    var Container = document.getElementById(object);
    if (Container == null) 
        return;
    
    Container.onkeyup = function(){
    
        checkMaxChar(Container, len, span, isShowAlert);
    }
    
    Container.onkeydown = function(){
    
        checkMaxChar(Container, len, span, isShowAlert);
    }
    Container.onblur = function(){
    
        checkMaxChar(Container, len, span, isShowAlert);
    }
    Container.onclick = function(){
    
        checkMaxChar(Container, len, span, isShowAlert);
    }
}

