Validation on filename

2 posts, 0 answers
  1. Paul
    Paul avatar
    26 posts
    Member since:
    Mar 2011

    Posted 22 Sep 2015 Link to this post

    Is there a way for me to validate the filename for any special characters and cancel the upload if it contains any special characters?
  2. Ivan Danchev
    Ivan Danchev avatar
    788 posts

    Posted 24 Sep 2015 Link to this post


    You can subscribe to the AsyncUpload's OnClientFileUploading client-side event, in its handler check the filename for presence of special characters and cancel the the event in case such are found:
    function OnClientFileUploading(sender, args) {
        var filename = args.get_fileName();
        var dotIndex = filename.lastIndexOf(".");
        var name = filename.substring(0 , dotIndex)
        if (/^[a-zA-Z0-9- ]*$/.test(name) == false) {
            alert('The filename contains special characters. The upload will be cancelled.');

    Ivan Danchev
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. DevCraft R3 2016 release webinar banner
Back to Top