This is a migrated thread and some comments may be shown as answers.

Validation on filename

1 Answer 51 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Iron
Paul asked on 22 Sep 2015, 03:27 PM
Is there a way for me to validate the filename for any special characters and cancel the upload if it contains any special characters?

1 Answer, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 24 Sep 2015, 11:13 AM
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
Tags
AsyncUpload
Asked by
Paul
Top achievements
Rank 1
Iron
Answers by
Ivan Danchev
Telerik team
Share this question
or