htc 로 검증 모듈 구현
7101 단어 htc 로 검증 모듈 구현
/***************************************************************************************
* validate1.0
* ocean , 、 、 ,
* 。 、 , 。
*
* , email to:[email protected]。
*
*
* http://www.oceanstudio.net
* ocean([email protected])
*****************************************************************************************/
//
<PUBLIC:ATTACH EVENT="onkeypress" ONEVENT="doEvent()" />
//
<PUBLIC:ATTACH EVENT="onpaste" ONEVENT="doEvent()" />
//
<PUBLIC:ATTACH EVENT="onblur" ONEVENT="doEvent()" />
<SCRIPT LANGUAGE="JScript">
//
var regArray = new Array(
new Array("int+0","^\\d+$",""," , "), // ( + 0)
new Array("int+","^[0-9]*[1-9][0-9]*$","^\\d+$"," , "), //
new Array("int-0","^((-\\d+)|(0+))$","^(-|(-\\d+)|(0+))$"," , "), // ( + 0)
new Array("int-","^-[0-9]*[1-9][0-9]*$","^(-|(-\\d+)|(0+))$"," , "), //
new Array("int","^-?\\d+$","^-|(-?\\d+)$"," , "), //
new Array("double+0","^\\d+(\\.\\d+)?$","^((\\d+\\.)|(\\d+(\\.\\d+)?))$"," , "), // ( + 0)
new Array("double+","^(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*))$","^((\\d+\\.)|(\\d+(\\.\\d+)?))$"," , "), //
new Array("double-0","^((-\\d+(\\.\\d+)?)|(0+(\\.0+)?))$","^(-|(-\\d+\\.)|(0+\\.)|(-\\d+(\\.\\d+)?)|(0+(\\.0+)?))$"," , "), // ( + 0)
new Array("double-","^(-(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*)))$","^(-|(-\\d+\\.?)|(-\\d+\\.\\d+))$"," , "), //
new Array("double","^(-?\\d+)(\\.\\d+)?$","^(-|((-?\\d+)(\\.\\d+)?)|(-?\\d+)\\.)$"," , "), //
new Array("char","^[A-Za-z]+$",""," , "), // 26
new Array("upperchar","^[A-Z]+$",""," , "), // 26
new Array("lowerchar","^[a-z]+$",""," , "), // 26
new Array("digitchar","^[A-Za-z0-9]+$",""," , "), // 26
new Array("digitchar_","^\\w+$",""," 、 , "), // 、26
new Array("email","^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$","^(([\\w-]+(\\.[\\w-]+)*@?)|([\\w-]+(\\.[\\w-]+)*@[\\w-]+)|([\\w-]+(\\.[\\w-]+)*@([\\w-]+\\.)+)|([\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+))$"," email , "), //email
new Array("url","^[a-zA-z]+://(\\w+(-\\w+)*)(\\.(\\w+(-\\w+)*))*(\\?\\S*)?$","^([a-zA-z]+:?)|([a-zA-z]+:/{1,2})|([a-zA-z]+://(\\w+(-\\w+)*))|([a-zA-z]+://(\\w+(-\\w+)*)(\\.(\\w+(-\\w+)*))*(\\?\\S*)?)$"," url , ") //url
);
//
function doEvent() {
//
var type = window.event.type;
// 。
var value = window.event.srcElement.value;
if (type == "keypress") { // ,
var keyCode = window.event.keyCode;
if (typeof(window.event.srcElement.upper) != "undefined") { //
if (keyCode >= 97 && keyCode <= 122)
keyCode = window.event.keyCode = keyCode - 32;
}
else if (typeof(window.event.srcElement.lower) != "undefined") { //
if (keyCode >= 65 && keyCode <= 90)
keyCode = window.event.keyCode = keyCode + 32;
}
value += String.fromCharCode(keyCode);
}
else if (type == "paste") {
value += window.clipboardData.getData("Text");
}
// , , 。
if (value == "") return;
// reg , 。
if (typeof(window.event.srcElement.reg) == "undefined") return;
// check ,
if ((type == "keypress" || type == "paste") && typeof(window.event.srcElement.check) == "undefined") return;
// ,
var msg = "";
//
var reg = window.event.srcElement.reg;
//
var regExp = null;
//
for (var i=0;i<regArray.length;i++) {
if (regArray[i][0] == reg) {
if ((type == "keypress" || type == "paste") && regArray[i][2] != "")
regExp = new RegExp(regArray[i][2]); //
else
regExp = new RegExp(regArray[i][1]); //
msg = regArray[i][3]; //
break; // ,
}
}
if (regExp == null) { // , reg 。
if ((type == "keypress" || type == "paste") && typeof(window.event.srcElement.regcheck) != "undefined")
regExp = new RegExp(window.event.srcElement.regcheck); // 。
else
regExp = new RegExp(reg); // 。
msg = " , "; //
}
// , 。
if (regExp.test(value)) return;
if (type == "blur") { // , 。
//
if (typeof(window.event.srcElement.msg) != "undefined")
msg = window.event.srcElement.msg;
//
alert(msg);
//
window.event.srcElement.focus();
window.event.srcElement.select();
}
else { // , 。
//
window.event.returnValue = false;
}
}
</SCRIPT>