Validation on filename

2 posts, 0 answers
  1. Paul
    Paul avatar
    27 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
    Admin
    Ivan Danchev avatar
    829 posts

    Posted 24 Sep 2015 Link to this post

    Hello,

    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.');
            args.set_cancel(true);
        }
    }


    Regards,
    Ivan Danchev
    Telerik
    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. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top