2010
05.02
05.02
A handy Windows 32 File name validator, recently I have been working with media files being saved from a Flex app and creating directories on windows machines for export for some Avid use, Windows has some funny constrains for file names, some examples include using the words [COM/n, CLOCK, CON], these are all included in the follwoing custom Validator with the usual ‘[$, *, etc]‘, hope it is useful to someone out in the wild.
The basic RegExp of the validator
internal function validateWin32( target:String ):Boolean { //Check name is not blank if( target.length < 1 ) { return false; } // Leading, trailing space, dot if (target.charAt( 0 ) == "." || target.charAt( 0 ) == " " || target.charAt( target.length ) == "." || target.charAt( target.length ) == " ") { return false; } // Multiple spaces if ( matchPart( target, "\\s\\s+" ) ) { return false; } // Explicitly illegal Windows characters if ( matchPart( target, "[$*\"/\\\\\\[\\]:;|=,]" ) ) { return false; } // Control characters if ( matchPart( target, "[\\x00-\\x1f]" ) ) { return false; } // Reserved names. DOS compatibility means that AUX.txt // is just as bad as AUX. if ( matchPart( target, "^(?i:CON|PRN|AUX|CLOCK\$|NUL|COM\\d|LPT\\d)(?:\\..*)?$" ) ) { return false; } return true; }