简体   繁体   中英

How to validate file input using Parsley JS?

I've used a custom validator to validate the file extension of a file input below.

.addValidator('filetype', function(value, requirement) {
    return value.split('.').pop().toLowerCase() === requirement;
})

I'd really like to get access to the actual file so I can check the MIME type. Is there a way to get a reference back to the input so I can check the actual file date?

Yes, the third argument is the parsley instance.

See this issue and this example

PRs for better documentation, as well as clean file validators in extra/ welcome.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM