ⓟrogramming/Java script

validateFileName

뚱땡이 우주인 2011. 1. 21. 19:16

The implementation MUST support at least the use of the following characters in file names:

- Letters (azAZ) - Numbers (0-9) - White spaces - Underscores ("_") - Hyphens ("-") - Dots (".")

 function validateFileName(fileName){
    var validReg=/^[\w- |.]*$/;
   
    return validReg.test(fileName);
}

- 응용을 해서 파일 이름에 '/' 가 지원 되도록 하는 스크립트 (즉 경로도 인정을 하겠다는 의미)
 function validateFileName(fileName){
 
 if (fileName.length == 0) {
  return false;
 }
 
    var validReg=/^[\w- |. |\/]*$/;
   
    return validReg.test(fileName);
}