js 인증 프레임 워 크 구현 코드 공유
1. 관건 적 인 방법 과 원리:
function check(thisInput)
if (!eval(scriptCode)) {
return false;
}
2. 호출 예시:
3. 검증 할 때 자동 으로 호출 됩 니 다: isNumeric 방법 과 notNull 방법 은 검 증 된 결과 정 보 를 되 돌려 줍 니 다.
4. 검증 프레임 소스 코드 는 다음 과 같다.
var ConfigValidateInfoType = "writeAlert"; // writeAlert writePage,"writePage;writeAlert"
var rmTempStatusIsAlert = false;
var rmTempStatusIsFocus = false;
var beginValidate = true;
var set_All_Venus_Inputs_Default = true;
String.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/g, ""); }
function checkAllForms(){
var checkResult = true;
rmTempStatusIsAlert = false;
rmTempStatusIsFocus = false;
setAllVenusInputsDefault();
for (var i=0;i=0 && thisInput.id.indexOf("_TF")>0 ) &&thisInput.clientWidth!=0&&thisInput.style&&thisInput.style.display!='none'){
/*
if(validateStr != null && validateStr.length > 0 ){
if(thisInput.tagName == 'TEXTAREA' && srcstr != '') {
srcstr = replaceEnter(srcstr);
if( thisInput.maxLength != null && thisInput.maxLength > 0 ){
if (getStrLength(srcstr) > thisInput.maxLength){
writeValidateInfo(thisInput, "
" +frm.maxLength+" ");
return false;
}
}
}
}
*/
if(thisInput.id&&thisInput.id.indexOf("supplier_id_ref_")!=-1&&document.getElementById("unionDiv")&&document.getElementById("unionDiv").style.display=="none"){
continue;
}
var rtValue = check(thisInput);
if(checkResult && rtValue == false) {
checkResult = false;
break;
}
}
}
}
return checkResult;
}
function check(thisInput) {
var validateStr = thisInput.validate;
if(validateStr == null) {
return true;
}
var inputValue = thisInput.value;
if ( beginValidate ) {
var validateTemp = new Array();
validateTemp = validateStr.split(';');
for (var i=0;i=0 && frm.id.indexOf("_TF")>0 ) ){
if(frm.validate != null) {
setVenusInputDefault(frm);
writeValidateInfoAfterObject("", frm);
}
}
}
}
return true;
}
function setVenusInputDefault(_frm) {
_frm.style.borderStyle="";
_frm.style.borderColor="";
if( _frm.value != null ){
_frm.style.backgroundColor = "";
_frm.style.color = "";
}
}
function replaceEnter(_str) {
/** **/
var str = _str;
str = str.replace('
','')
str = str.replace('\r','')
//alert(str.indexOf('
'))
if(str.indexOf('
')!=-1 &&str.indexOf('\r')!=-1) {
return replaceEnter(str);
} else {
return str;
}
}
function replaceSingleQuote(_str) {
/** **/
var str = _str;
str = str.replace('\\','\\u005C');
str = str.replace('\'','\\u0027');
str = str.replace('(','\\u0028');
str = str.replace(')','\\u0029');
str = str.replace('\"','\\u0022');
str = str.replace(';','\\u0038');
//str = Jtrim(str);
return str;
}
function isContains(_validateStr,_validator) {
for (var i=0;i<_validatestr.length if="" _validator="" return="" true="" false="" function="" writevalidateinfo="" thisobj="" var="" inputname="getInputNameFromObject(thisObj);" info="inputName">= 0) {
writeValidateInfoAfterObject(info, thisObj);
}
if(ConfigValidateInfoType.indexOf("writeAlert") >= 0) {
writeValidateInfoAlert(info, thisObj);
}
if(!rmTempStatusIsFocus) {
setVenusInputError(thisObj);
rmTempStatusIsFocus = true;
}
}
function setVenusInputError(_frm) {
try {
//_frm.click(); // click
_frm.focus();
// SELCET , , ,
// : 2009-11-12
if(_frm.tagName!="SELECT"){
_frm.select();
}
_frm.style.borderStyle="dashed";
_frm.style.borderColor="rgb(255,50,0)";
if( _frm.value != null && _frm.value.length > 0 ){
_frm.style.backgroundColor = "highlight";
_frm.style.color = "white";
}
} catch(e) {
alert(e.message);
}
}
function writeValidateInfoAlert(info, thisObj) {
if(!rmTempStatusIsAlert) {
alert(info);
rmTempStatusIsAlert = true;
}
}
function writeValidateInfoAfterObject(info, thisObj) { //
var validateInfoObj = null;
thisObj = getValidatePosition(thisObj);
if(thisObj.nextSibling != null && thisObj.nextSibling.nextSibling != null
&& thisObj.nextSibling.tagName != null && thisObj.nextSibling.tagName.toUpperCase() == "FONT"
&& thisObj.nextSibling.nextSibling.tagName.toUpperCase() == "SPAN" && thisObj.nextSibling.nextSibling.className == "font_remain_prompt") {
validateInfoObj = thisObj.nextSibling.nextSibling;
} else {
thisObj.insertAdjacentHTML("afterEnd", "");
validateInfoObj = thisObj.nextSibling.nextSibling;
}
if(validateInfoObj.innerHTML.length > 0 || info.length > 0) {
validateInfoObj.innerHTML = info;
}
}
function getValidatePosition(thisObj) {
if(thisObj.nextSibling != null && thisObj.nextSibling.className == "refButtonClass") {
thisObj = getValidatePosition(thisObj.nextSibling);
} else if(thisObj.nextSibling != null && thisObj.nextSibling.type == "hidden"){
thisObj = getValidatePosition(thisObj.nextSibling);
}
return thisObj;
}
function getInputNameFromObject(thisInput) {
var inputName = thisInput.inputName ;
if ( inputName == null || inputName.length == 0 ){
inputName = thisInput.name;
if ( inputName == null || inputName.length == 0 ){
inputName = "";
}
}
return inputName;
}
function getStrLength(str){
var len = 0;
for(var i=0;i 255)
len += 2;
else
len ++;
}
return len;
}
/**********************************************************************
*ranmin validate
***********************************************************************/
function notNull(s, thisInput) { //
//
try{
thisInput.value=thisInput.value.trim();
}catch(e){
}
s=s.trim();
if (s.length == 0){
writeValidateInfo(" !", thisInput);
return false;
}
var s = Jtrim(s);
if ( s.length == 0){
writeValidateInfo(" !", thisInput);
return false;
}
return true;
}
function isJine(s, thisInput) { //
var a=/^[0-9]*(\.[0-9]{1,2})?$/;
if(!a.test(s)){
writeValidateInfo(" ", thisInput);
return false;
}else{
return true;
}
}
function isMobile(s, thisInput) { // : , , “-”
//
try{
thisInput.value=thisInput.value.trim();
}catch(e){
}
s=s.trim();
if(s.length ==0){
return true;
}
var obj=new Array()
obj[0]="13";
obj[1]="14";
obj[2]="15";
obj[3]="18";
if(s != null ){
if(s.length != 11){
writeValidateInfo(' !', thisInput);
return false;
}
var mob = 0;
for ( var int = 0; int < obj.length; int++) {
if(s.substring(0,2) == obj[int]){
mob = mob+1;
}
}
if(mob == 0){
writeValidateInfo(' !', thisInput);
return false;
}
}
var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;
if (!patrn.exec(s)) {
writeValidateInfo(' !', thisInput);
return false;
}
return true;
}
function isPostalCode(s, thisInput) { //
//
try{
thisInput.value=thisInput.value.trim();
}catch(e){
}
s=s.trim();
if(s.length ==0){
return true;
}
var patrn=/^[a-zA-Z0-9 ]{3,12}$/;
if (!patrn.exec(s)) {
writeValidateInfo(' !', thisInput);
return false;
}
return true;
}
function isTel(s,thisInput) { // 、 : “+” , , “-”
//
try{
thisInput.value=thisInput.value.trim();
}catch(e){
}
s=s.trim();
if(s.length ==0){
return true;
}
var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;
if (!patrn.exec(s)) {
writeValidateInfo(' !',thisInput);
return false
}
return true;
}
function isTelForFax(s,thisInput) { // 、 : “+” , , “-”
//
try{
thisInput.value=thisInput.value.trim();
}catch(e){
}
s=s.trim();
if(s.length ==0){
return true;
}
var patrn=/^(\d){3,4}[-](\d){7,8}$/;
if (!patrn.exec(s)) {
writeValidateInfo(' , :010-88888888!',thisInput);
return false
}
return true;
}
function isFax(s,thisInput) { // 、 : “+” , , “-”
//
try{
thisInput.value=thisInput.value.trim();
}catch(e){
}
s=s.trim();
if(s.length ==0){
return true;
}
var patrn=/^(\d){3,4}[-](\d){7,8}$/;
if (!patrn.exec(s)) {
writeValidateInfo(' , :010-88888888!',thisInput);
return false
}
return true;
}
function isChinese(s,thisInput) { //
//
try{
thisInput.value=thisInput.value.trim();
}catch(e){
}
s=s.trim();
if(s.length ==0){
return true;
}
var ret = ischinese(s);
if(!ret){
writeValidateInfo(" ", thisInput);
return ret;
}
return ret;
}
function notChinese(s,thisInput) { //
//
try{
thisInput.value=thisInput.value.trim();
}catch(e){
}
s=s.trim();
if(s.length ==0){
return true;
}
var ret = ischinese(s);
if(ret){
writeValidateInfo(" ",thisInput);
return false;
}
return true;
}
function isNum(s,thisInput) { //
//
try{
thisInput.value=thisInput.value.trim();
}catch(e){
}
s=s.trim();
if(s.length ==0){
return true;
}
var digits = "0123456789";
var i = 0;
var sLength = s.length;
while ((i < sLength)) {
var c = s.charAt(i);
if (digits.indexOf(c) == -1){
writeValidateInfo (" !",thisInput);
return false;
}
i++;
}
return true;
}
function isNumBigtoZero(s,thisInput) { //
//
try{
thisInput.value=thisInput.value.trim();
}catch(e){
}
s=s.trim();
if(s.length ==0){
return true;
}
var digits = "0123456789";
var i = 0;
var sLength = s.length;
while ((i < sLength)) {
var c = s.charAt(i);
if (digits.indexOf(c) == -1){
writeValidateInfo (" !",thisInput);
return false;
}
i++;
}
try{
if(thisInput.value<=0){
writeValidateInfo (" !",thisInput);
return false;
}
}catch(e){
}
return true;
}
function isEmail(s,thisInput) { //
//
try{
thisInput.value=thisInput.value.trim();
}catch(e){
}
s=s.trim();
if(s.length ==0){
return true;
}
if (s.length > 100) {
writeValidateInfo("email 100 !",thisInput);
return false;
}
var regu = /^(([0-9a-zA-Z]+)|([0-9a-zA-Z]+[_.0-9a-zA-Z-]*[0-9a-zA-Z]+))@([a-zA-Z0-9-]+[.])+([a-zA-Z]{2}|net|NET|com|COM|gov|GOV|mil|MIL|org|ORG|edu|EDU|int|INT)$/;
if (regu.exec(s)) {
return true;
} else {
writeValidateInfo (" E-mail !",thisInput);
return false;
}
}
function isIP() { // IP
var patrn=/^[0-9.]{1,20}$/;
if (!patrn.exec(s)){
writeValidateInfo(' IP !',thisInput);
return false
}
return true;
}
/**********************************************************************
*Venus Web JavaScript Code:HTC notNull
***********************************************************************/
function notNullWithoutTrim(s,thisInput) { // ""
//
try{
thisInput.value=thisInput.value.trim();
}catch(e){
}
s=s.trim();
if ( s.length == 0){
writeValidateInfo(' , !',thisInput);
return false;
}
return true;
}
function isInteger(str,thisInput) { //
//
try{
thisInput.value=thisInput.value.trim();
}catch(e){
}
str=str.trim();
if(str.length ==0){
return true;
}
var reg = "0123456789";
for (var i=0;i" || s.substring(0,1) == " "){
writeValidateInfo(" ",thisInput);
return false;
}
if (!HoldCode(s)){
writeValidateInfo(" \"・\"/\"―\"/\"――\" ",thisInput);
return false;
}
if (s.trim().length > 0){
if (s.indexOf("\"") > -1){
writeValidateInfo(" !!",thisInput);
return false;
}
if (s.indexOf("\'") > -1){
writeValidateInfo(" ",thisInput);
return false;
}
if (s.indexOf("\\") > -1){
writeValidateInfo(" '\\' ",thisInput);
return false;
}
}
return true;
}
//
function Jtrim(str) { //
var i = 0;
var len = str.length;
if ( str == "" ) return( str );
var j = len -1;
var flagbegin = true;
var flagend = true;
while ( flagbegin == true && i< len) {
if ( str.charAt(i) == " " ) {
i=i+1;
flagbegin=true;
} else {
flagbegin=false;
}
}
while (flagend== true && j>=0) {
if (str.charAt(j)==" ") {
j=j-1;
flagend=true;
} else {
flagend=false;
}
}
if ( i > j )
return ("");
var trimstr = str.substring(i,j+1);
return trimstr;
}
function isNumber(s) { //
s=s.trim();
if(s.length ==0){
return true;
}
var digits = "0123456789";
var i = 0;
var sLength = s.length;
while ((i < sLength)) {
var c = s.charAt(i);
if (digits.indexOf(c) == -1) {
return false;
}
i++;
}
return true;
}
function ischinese(s) { //
var ret=true;
for(var i=0;i=10000);
return ret;
}
/**********************************************************************
*Venus Web JavaScript Code:HTC ( )
***********************************************************************/
function HoldCode(str){
for(var i=0;i" || current_form[i].value.substring(0,1) == " "){
alert(" ");
current_form[i].focus();
current_form[i].select();
return false;
}
if (getStrLength(current_form[i].value) > current_form[i].maxLength){
alert("
" +current_form[i].maxLength+" ");
current_form[i].focus();
current_form[i].select();
return false;
}
if (!HoldCode(current_form[i].value)){
alert(" \"・\"/\"―\"/\"――\" ");
current_form[i].focus();
current_form[i].select();
return false;
}
if (!is_empty(current_form[i].value)){
if (current_form[i].name == "scriptDefine"){
return true;
}
if (current_form[i].value.indexOf("\"") > -1){
alert(" ");
current_form[i].focus();
current_form[i].select();
return false;
}
}
}
}
return true;
}
function checkNumber(s, inputName) {
try{
//
try{
thisInput.value=thisInput.value.trim();
}catch(e){
}
s=s.trim();
if(s.length ==0){
return true;
}
var thisObj = event.srcElement;
var maxLength = thisObj.integerDigits;
var scale = thisObj.decimalDigits;
return checkNumberImpl(s, maxLength, scale);
}catch(e){
}
}
function checkNumberImpl(s, maxLength, scale) { // , , 10-2
if(s == "") {
return true;
}
if(scale == undefined) {
scale = 0;
}
if(maxLength == undefined) {
maxLength = 38;
}
if(!isFloatNumber(s)) {
return false;
}
if(s.indexOf(".") >0) {
if(s.indexOf(".") <= maxLength && (Math.round(s*(pow(10,scale)))/?]{1}[^`~!@$%^&()+=|\\\][\]\{\}:;'\,.<>?]{0,5000}$/;
var patrn2 = /[^\{\|\.\\,<>"'_}/]/;
if (!patrn.exec(s) || !patrn2.exec(s)){
writeValidateInfo(' , !',thisInput);
return false;
}
return true ;
}
//===============================================================================================
/**
* ( ).
*/
function isNumeric(value, thisInput) {
//
try{
thisInput.value=thisInput.value.trim();
}catch(e){
}
value=value.trim();
if(value.length ==0){
return true;
}
var reg = /^\d+(\.\d+)?$/;
if (!reg.test(value)) {
writeValidateInfo (" !", thisInput);
return false;
}
return true;
}
/**
* ( ).
*/
function checkInt(value, thisInput) {
//
try{
thisInput.value=thisInput.value.trim();
}catch(e){
}
value=value.trim();
if(value.length ==0){
return true;
}
var reg = /^[0-9]\d*$/;
if (!reg.test(value)) {
writeValidateInfo (" !", thisInput);
return false;
}
return true;
}
/**
* ( 10 , )
*/
function validateNumericAndLength(value, thisInput) {
//
try{
thisInput.value=thisInput.value.trim();
}catch(e){
}
value=value.trim();
if(value.length ==0){
return true;
}
var reg = /^\d{1,10}(\.\d+)?$/;
if (!reg.test(value)) {
writeValidateInfo (" ( 10 )!", thisInput);
return false;
}
return true;
}
/**
* (18,2)
*/
function isNum18p2(value, thisInput) {
//
try{
thisInput.value=thisInput.value.trim();
}catch(e){}
value=value.trim();
if(value.length ==0){
return true;
}
var reg = /^(-)?\d{1,16}(\.\d{1,2})?$/;
if (!reg.test(value)) {
writeValidateInfo (" ( 16 , 2 )!", thisInput);
return false;
}
return true;
}
/**
* (18,4)
*/
function isNum18p4(value, thisInput) {
//
try{
thisInput.value=thisInput.value.trim();
}catch(e){}
value=value.trim();
if(value.length ==0){
return true;
}
var reg = /^(-)?\d{1,14}(\.\d{1,4})?$/;
if (!reg.test(value)) {
writeValidateInfo (" ( 14 , 4 )!", thisInput);
return false;
}
return true;
}
/**
* (5,2)
*/
function isNum5p2(value, thisInput) {
//
try{
thisInput.value=thisInput.value.trim();
}catch(e){}
value=value.trim();
if(value.length ==0){
return true;
}
var reg = /^(-)?\d{1,3}(\.\d{1,2})?$/;
if (!reg.test(value)) {
writeValidateInfo (" ( 3 , 2 )!", thisInput);
return false;
}
return true;
}
/**
* Email.
*/
function checkEmail(value, thisInput) {
//
try{
thisInput.value=thisInput.value.trim();
}catch(e){
}
value=value.trim();
if(value.length ==0){
return true;
}
var reg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
if (!reg.test(value)) {
writeValidateInfo (" Email !", thisInput);
return false;
}
return true;
}
/**
* (15 18 ).
*/
function checkIdCard(value, thisInput) {
//
try{
thisInput.value=thisInput.value.trim();
}catch(e){
}
value=value.trim();
if(value.length ==0){
return true;
}
var reg = /^\d{15}(\d{2}[A-Za-z0-9])?$/;
if (!reg.test(value)) {
writeValidateInfo (" !", thisInput);
return false;
}
return true;
}
/**
* .
*/
function checkPostCode(value, thisInput) {
//
try{
thisInput.value=thisInput.value.trim();
}catch(e){
}
value=value.trim();
if(value.length ==0){
return true;
}
var reg = /^[0-9]\d{5}$/;
if (!reg.test(value)) {
writeValidateInfo (" !", thisInput);
return false;
}
return true;
}
/**
* .
*/
function checkChinese(value, thisInput) {
//
try{
thisInput.value=thisInput.value.trim();
}catch(e){
}
value=value.trim();
if(value.length ==0){
return true;
}
var reg = /^[\u0391-\uFFE5]+$/;
if (!reg.test(value)) {
writeValidateInfo (" !", thisInput);
return false;
}
return true;
}
/**
* .
*/
function checkInvalidString(value, thisInput) {
var reg = /^[^`~!@#$%^&*()+=|\\\][\]\{\}:;'\,.<>/?]*$/;
if (!reg.exec(value)) {
writeValidateInfo (" , !", thisInput);
return false;
}
return true;
}
function checkMoney(s, inputName) {
//
try{
thisInput.value=thisInput.value.trim();
}catch(e){
}
s=s.trim();
if(s.length ==0){
return true;
}
if(s==""){
writeValidateInfo(" !", inputName);
return false;
}
if(isFloatNumber(s,inputName)==false){
writeValidateInfo(" !", inputName);
return false;
}
var maxLength = 10;
var scale =2;
return checkNumberImpl(s, maxLength, scale,inputName);
}
/**
* 0-100
*/
function isAdultAge(str,thisInput) { //
//
try{
thisInput.value=thisInput.value.trim();
}catch(e){
}
str=str.trim();
if(str.length ==0){
return true;
}
if(parseInt(str)<0 || parseInt(str)>100){
writeValidateInfo(' (0--100 )!',thisInput);
return false;
}
return true;
}
/**
* 6 ( 、 、 、 、 >=6、 >=10)
* , 0
*/
function pwdStrength(pwd) {
var sum = [0, 0, 0];
for (var i=0; i=48 && c <=57) //
sum[0] = 1;
else if (c >=65 && c <=90) //
sum[1] = 1;
else if (c >=97 && c <=122) //
sum[1] = 1;
else //
sum[2] = 1;
}
var level = sum[0] + sum[1] + sum[2] ;
if (pwd.length >= 8) level++;
return level;
}
function isBiggerZero(value, thisInput) { // , 0
if(thisInput.value<=0){
writeValidateInfo(' !',thisInput);
return false;
}
return true;
}
function isNonnegative(value, thisInput) {
if(thisInput.value<0){
writeValidateInfo(' !',thisInput);
return false;
}
return true;
}
/**
* (20,6)
*/
function isNum20p6(value, thisInput) {
//
try{
thisInput.value=thisInput.value.trim();
}catch(e){}
value=value.trim();
if(value.length ==0){
return true;
}
var reg = /^(-)?\d{1,14}(\.\d{1,6})?$/;
if (!reg.test(value)) {
writeValidateInfo (" ( 14 , 6 )!", thisInput);
return false;
}
return isBiggerZero(value, thisInput);
}
/**
* (18,6)
*/
function isNum18p6(value, thisInput) {
//
try{
thisInput.value=thisInput.value.trim();
}catch(e){}
value=value.trim();
if(value.length ==0){
return true;
}
var reg = /^(-)?\d{1,12}(\.\d{1,6})?$/;
if (!reg.test(value)) {
writeValidateInfo (" ( 12 , 6 )!", thisInput);
return false;
}
return isBiggerZero(value, thisInput);
}
function isNonnegative20p6(value, thisInput) {
//
try{
thisInput.value=thisInput.value.trim();
}catch(e){}
value=value.trim();
if(value.length ==0){
return true;
}
var reg = /^(-)?\d{1,14}(\.\d{1,6})?$/;
if (!reg.test(value)) {
writeValidateInfo (" ( 14 , 6 )!", thisInput);
return false;
}
return isNonnegative(value, thisInput);
}
/**
* (20,4)
*/
function isNum20p4(value, thisInput) {
//
try{
thisInput.value=thisInput.value.trim();
}catch(e){}
value=value.trim();
if(value.length ==0){
return true;
}
var reg = /^(-)?\d{1,16}(\.\d{1,4})?$/;
if (!reg.test(value)) {
writeValidateInfo (" ( 16 , 4 )!", thisInput);
return false;
}
return isBiggerZero(value, thisInput);
}
/**
*
*/
function isDPCBZJ(value, thisInput) {
//
try{
thisInput.value=thisInput.value.trim();
}catch(e){
}
value=value.trim();
if(value.length ==0){
return true;
}
var reg = /^[1-9]\d*00$/;
if (!reg.test(value)) {
writeValidateInfo (" !", thisInput);
return false;
}
return true;
}
//
function validateYear(startYear,endYear,flag) {
if(startYear > endYear){
if(flag==1){
alert(" ");
return false;
}else{
alert(" ");
return false;
}
}
return true;
}
이상 은 본문의 전체 내용 이 므 로 여러분 의 학습 에 도움 이 되 기 를 바 랍 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.