输入类型='文件'接受pdf和excel文件扩展名

时间:2018-06-04 18:01:22

标签: javascript file validation input

我希望输入 import Foundation import FirebaseAuth typealias LoginHandler = (_ msg: String?) -> Void; struct LoginErrorCode { static let INVALID_EMAIL = "Invalid Email"; static let WRONG_PASSWORD = "Wrong Password"; static let PROBLEM_CONNECTING = "Problem Connecting"; static let USER_NOT_FOUND = "User not found" static let EMAIL_ALREADY_IN_USE = "Email Already in Use"; static let WEAK_PASSWORD = "Weak Password"; } class AuthProvider { private static let _instance = AuthProvider(); static var Instance: AuthProvider { return _instance; } func login(withEmail: String, password: String, loginHandler: LoginHandler?){ Auth.auth().signIn(withEmail: withEmail, password: password, completion: {(user, error) in if error != nil { self.handleErrors(err: error as! NSError, loginHandler: loginHandler) } else { loginHandler?(nil); } }); } func signUp(withEmail: String, password: String, loginHandler: LoginHandler?){ Auth.auth().createUser(withEmail: withEmail, password: password) { (user, error) in if error != nil { self.handleErrors(err: error as! NSError, loginHandler: loginHandler); } else { if user?.user.uid != nil { self.login(withEmail: withEmail, password: password, loginHandler: loginHandler); } } }; } private func handleErrors(err: NSError, loginHandler: LoginHandler?){ if let errCode = AuthErrorCode(rawValue: err.code){ switch errCode { case .wrongPassword: loginHandler?(LoginErrorCode.WRONG_PASSWORD); break; case .invalidEmail: loginHandler?(LoginErrorCode.INVALID_EMAIL); break; case .userNotFound: loginHandler?(LoginErrorCode.USER_NOT_FOUND); break; case .emailAlreadyInUse: loginHandler?(LoginErrorCode.EMAIL_ALREADY_IN_USE); break; case .weakPassword: loginHandler?(LoginErrorCode.WEAK_PASSWORD); break; default: loginHandler?(LoginErrorCode.PROBLEM_CONNECTING); break; } } } 仅接受pdf和excel

我做了type="file"

它接受.pdf和.xls文件,但不接受.xlsx,我怎么能让它接受xlsx文件呢?

2 个答案:

答案 0 :(得分:2)

尝试使用此功能并告诉我们!

   <input type="file" accept=".pdf,.xls" />

修改 简单

<input type="file" accept="add all the extension of your choice separating by a comma " />

答案 1 :(得分:1)

请尝试以下操作:

<input type="file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />

在现代浏览器中,您还可以直接使用文件扩展名,如:

accept=".pdf, .xls, .xlsx"