/////////////////////////////////////////////////////////////////////////////////////////////////// //// String Validierungsfunktionen /////////////////////////////////////////////////////////////////////////////////////////////////// function validateString( inputValue, fieldName, inputFormat, minLength, maxLength, possCharacter, possList, impossList) { return validateString2( inputValue, fieldName, inputFormat, minLength, maxLength, possCharacter, possList, impossList,true,''); } function validateStringBetter( inputValue, fieldName, inputFormat, inputFormatView, minLength, maxLength, possCharacter, possList, impossList) { return validateString2( inputValue, fieldName, inputFormat, minLength, maxLength, possCharacter, possList, impossList,false,inputFormatView); } function validateString2( inputValue, fieldName, inputFormat, minLength, maxLength, possCharacter, possList, impossList,oldFormat,inputFormatView) { // TODO: Format wird momentan nicht interpretiert var internValue = inputValue.value; var tmValue = internValue + 'a'; if ( tmValue.length == 1 ) { return true; } var errorDetected = false; if ( oldFormat ) { if ( inputFormat.length != 0 && !checkStringFormat(fieldName, internValue, inputFormat)) { errorDetected = true; } } else { if ( inputFormat.length != 0 && !checkStringFormatBetter(fieldName, internValue, inputFormat,inputFormatView)) { errorDetected = true; } } if ( !checkStringMinLength(fieldName, internValue, minLength)) { errorDetected = true; } if ( !checkStringMaxLength(fieldName, internValue, maxLength)) { errorDetected = true; } if ( !checkStringPossCharacter(fieldName, internValue, possCharacter)) { errorDetected = true; } if ( !checkStringPossList(fieldName, internValue, possList)) { errorDetected = true; } if ( !checkStringImpossList(fieldName, internValue, impossList)) { errorDetected = true; } // Wenn irgendwo ein Fehler aufgetreten ist dann Focus setzen damit korrigiert werden kann if ( errorDetected ) { inputValue.focus(); inputValue.select(); return false; } return true; } function checkStringFormat(fieldName, inputValue, inputFormat) { var reg = eval("/^" + inputFormat + "$/"); var result = inputValue.match(reg); if (!result ) { var msg = "Eingabe für arg0 entspricht nicht dem vorgegebenen Format arg1"; msg = msg.replace( /arg0/, fieldName); msg = msg.replace( /arg1/, inputFormat); alert(msg); return false; } return true; } function checkStringFormatBetter(fieldName, inputValue, inputFormat,inputFormatView) { var reg = eval("/^" + inputFormat + "$/"); var result = inputValue.match(reg); if (!result ) { var msg = "Das Format der Eingabe für arg0 entspricht nicht der Vorgabe: arg1"; msg = msg.replace( /arg0/, fieldName); msg = msg.replace( /arg1/, inputFormatView); alert(msg); return false; } return true; } function checkStringMinLength(fieldName, inputValue, minLength) { if ( minLength != null ) { // Damit man nicht bevormundet wird es sei doch eine Zahl var tmp = "/" + inputValue; if ( tmp.length < (minLength +1) ) { var msg = "Feld arg0 muss mindestens arg1 Zeichen enthalten"; msg = msg.replace( /arg0/, fieldName); msg = msg.replace( /arg1/, minLength); alert(msg); return false; } } return true; } function checkStringMaxLength(fieldName, inputValue, maxLength) { if ( maxLength != null ) { // Damit man nicht bevormundet wird es sei doch eine Zahl var tmp = "/" + inputValue; if ( tmp.length > (maxLength +1) ) { var msg = "Feld arg0 darf maximal arg1 Zeichen enthalten"; msg = msg.replace( /arg0/, fieldName); msg = msg.replace( /arg1/, maxLength); alert(msg); return false; } } return true; } function checkStringPossCharacter(fieldName, inputValue, possCharacter) { if ( possCharacter != null ) return true; return true; } function checkStringPossList(fieldName, inputValue, possList) { if ( possList != null ) { found = false; var values=""; var delim =" "; for ( var i=0; i < possList.length; i++ ) { if ( possList[i] == inputValue ) { found = true; } else { values = values + delim + possList[i]; delim = ", "; } } if ( !found ) { var msg = "Es sind nur folgende Werte für arg0 erlaubt: arg1"; msg = msg.replace( /arg0/, fieldName); msg = msg.replace( /arg1/, values); alert(msg); return false; } } return true; } function checkStringImpossList( fieldName, inputValue, impossList) { if ( impossList != null ) { found = false; var values=""; var delim =" "; for ( var i=0; i < impossList.length; i++ ) { if ( impossList[i] == inputValue ) { found = true; } values = values + delim + impossList[i]; delim = ", "; } if ( found ) { var msg = "Folgende Werte sind für arg0 nicht erlaubt: arg1"; msg = msg.replace( /arg0/, fieldName); msg = msg.replace( /arg1/, values); alert(msg); return false; } } return true; }