1

I've been struggling with a strange syntax error since yesterday: The FF debugger keeps saying "SyntaxError: illegal character" at this specific line :

function newTimePeriod(ID, param, paramID, unit)
{
    updateSession();
    //check if date
    //(I got this regex from another post)
    var re = new RegExp("^\\d{4,4}(-\\d{1,2}){1,2}( \\d{1,2}(:\\d{1,2}){1,2})?$");

    var dateFrom = document.getElementById("chart_date_min_" + ID).value;
    var dateTo = document.getElementById("chart_date_max_" + ID).value;
    var fromCorrect = re.test(dateFrom);  
    var toCorrect = re.test(dateFrom);  
    /**/if (fromCorrect && toCorrect)​{/**/   //return illegal character
    LoadGraph(ID, param, paramID, unit, dateFrom, dateTo);
    }
}

I tried to include this script into the main php page, or separate it; it doesn't change a thing. Charset used is UTF-8, and fromCorrect and toCorrect returns booleans correctly (the regex is working)

When I remove the if statement the script is loading... Notepad++ doesn't show any special characters hiding anywhere.

Any thoughts?

Bathsheba
  • 231,907
  • 34
  • 361
  • 483
Sciid
  • 39
  • 1
  • 10
  • I think/hope OP added the ** to show which line the error is in. – afaf12 Dec 21 '13 at 11:45
  • Can you also provide the html for this specially dateFrom and dateTo – Raunak Kathuria Dec 21 '13 at 11:48
  • There is an invisible space between `)` and `{`. Delete the line and re-write it (*don't* copy-paste). – JJJ Dec 21 '13 at 11:53
  • possible duplicate of [SyntaxError: Unexpected token ILLEGAL](http://stackoverflow.com/questions/12719859/syntaxerror-unexpected-token-illegal) – JJJ Dec 21 '13 at 11:54
  • If you are interested in what non-printable character caused the error, then you could copy the line in question into a HEX editor. The HEX view of (g)vim is quite helpful for those kinds of problem. – Ralf Dec 21 '13 at 12:21

2 Answers2

5

I have copied your code into a fiddle - seems you have a zero-width space between the braces:

if (fromCorrect && toCorrect)​{
                             ^
janfoeh
  • 10,243
  • 2
  • 31
  • 56
3

The good way to solve weird characters creeping in from copying and pasting is to manually re-type the line in question.

Lex Podgorny
  • 2,598
  • 1
  • 23
  • 40
  • Thanks a lot, it works perfectly now! I though notepad++ was able to display such characters... – Sciid Dec 21 '13 at 12:58