OnClientFileSelected filename validation

2 posts, 0 answers
  1. Yuly
    Yuly avatar
    1 posts
    Member since:
    Nov 2015

    Posted 01 Sep 2016 Link to this post

    Please bear with me, as this is my first post.

    I am trying to do a clientside validation on filename expression. I do not want to have :, /, %, etc in my file names. How do you guys do that?

  2. Ivan Danchev
    Ivan Danchev avatar
    1993 posts

    Posted 05 Sep 2016 Link to this post

    Hello Yuly,

    You can prevent the upload of files with names containing special characters, "/%" for example, by subscribing to the AsyncUpload's OnClientFileUploading event and cancelling the event in case the filename contains a forbidden character:
    function OnClientFileUploading(sender, args) {
        var fileName = args.get_fileName();
        if (!isValid(fileName)) {
    function isValid(str) {
        return !/[~`!#$%\^&*+=\-\[\]\\';,/{}|\\":<>\?]/g.test(str);

    The event will fire for every selected file, so in case you are selecting multiple files (MultipleFileSelection="Automatic") the event will be cancelled only for those with special characters in their name. 

    Ivan Danchev
    Telerik by Progress
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top