INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Syntax Error: Unexpected token { after a regular expression test
2

Syntax Error: Unexpected token { after a regular expression test

Syntax Error: Unexpected token { after a regular expression test

(OP)
Hi,
I have what I hope is a simple question. :) The chrome debugger is giving me an error in my validation code:
Uncaught SyntaxError: Unexpected token {

The error is on the "{" line in the below code:

CODE --> javascript

if ((document.forms.regform.graddate.value.length > 0) && ( !/^\d{2}\/\d{2}$/.test(document.forms.regform.graddate.value) ) //graddate mm/yy
  {
    alert("Graduation date must be in format mm/yy to continue.");
    return false;
  } 

Any simple fix? Many thanks!

Katie

RE: Syntax Error: Unexpected token { after a regular expression test

(OP)
Oh, FYI, I just tried replacing the above code with this:

CODE --> javascript

//graddate mm/yy
 var patt = new RegExp("/^\d{2}\/\d{2}$/");
 if ((document.forms.regform.graddate.value.length > 0) && ( !patt.test(document.forms.regform.graddate.value) )
  {
    alert("Graduation date must be in format mm/yy to continue.");
    return false;
  } 

No dice. Same error. I know it must be something simple; I'm just not seeing it. :\

Many thanks again!

Katie

RE: Syntax Error: Unexpected token { after a regular expression test

Hi

Missing closing parenthesis ( ) ) :

CODE --> JavaScript

// ,------------------------------------------------------------- 1 ---------------------------------------------------------???
// |,---------------------- 2 -----------------------.    ,------------------------------ 2 ------------------------------.
// ||                                                |    |                       ,----------------- 3 ----------------.  |
// ||                                                |    |                       |                                     | |
if ((document.forms.regform.graddate.value.length > 0) && ( !/^\d{2}\/\d{2}$/.test(document.forms.regform.graddate.value) ) //graddate mm/yy
  {
    alert("Graduation date must be in format mm/yy to continue.");
    return false;
  } 

Feherke.
feherke.ga

RE: Syntax Error: Unexpected token { after a regular expression test

(OP)
Huh. You are right. Thank you.

(I say, "huh," because that's the first thing I checked for. And the second, and the third... and somehow, I counted the parentheses wrong every time. Even after you counted them for me, it took me a while to see it. I'm sick, and my mind is fuzzy. I'm sticking with that story. smile )

Thanks again!

Katie

RE: Syntax Error: Unexpected token { after a regular expression test

Hi

A hint : try other browsers too. Personally I find Chrome's message abit unclear.

Quote (FireBug Console)

 X  SyntaxError: missing ) after condition
{

Quote (Opera Dragonfly Console)


if ((document.forms.regform.graddate.value.length > 0) && ( !/^\d{2}\/\d{2}$/.test(document.forms.regform.graddate.value) ) //graddate mm/yy
{
Syntax error at line 23 while loading: expected ')', got '{'
  {
--^

Feherke.
feherke.ga

RE: Syntax Error: Unexpected token { after a regular expression test


Incidentally, you might want to change this:

CODE

d{2} 

to this:

CODE

d{1,2} 

That would allow both single and double digits to be entered - which as a user, I'd find a far nicer experience (why force someone to enter "02" when they can enter "2"?)

Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

@ Code Couch: http://www.codecouch.com/dan/

@ Twitter: http://twitter.com/SleepyDrunkDan

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close