www.webdeveloper.com
Results 1 to 4 of 4

Thread: match(/text.*/) fails

Hybrid View

  1. #1
    Join Date
    Feb 2013
    Posts
    6

    match(/text.*/) fails

    I have the following code line

    Code:
     if(!that.type.match(/text.*/))
    It fail no matter what kind of a file it is.

    Code:
    	
    if(that.files && that.files[0]){
    	var reader = new FileReader();
    	var output;
    	var textType = /text.*/;
    
    	var f = that.files[0];
    	
    // tested with .txt and .jpg.
    // in both cases "!that.type.match(/text.*/)" returns true.
    
    // What am I doing wrong?
    	
    	if(!that.type.match(/text.*/)) {
    		var name = f.name;
    		var msg = "Obituary file must be a text file.<br />";
    		msg += "File " + name + " is not a text file.";
    			
    		document.getElementById('errdisplay').innerHTML = msg;
    	}
    }

  2. #2
    Join Date
    Jul 2011
    Posts
    127
    What is the value of that.type?

  3. #3
    Join Date
    Feb 2013
    Posts
    6
    Using alert(that.type); I get "file"

  4. #4
    Join Date
    Jul 2011
    Posts
    127
    So match works correct in your case. Your string ("file") does not contain substr "text", so match returns null, that is casted to false, but as you have ! before match it becomes true.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles