views:

29

answers:

2

Hi I have an input on my page:

onclick="return tagList.addTag(true,'/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/')"

then I have some code that wants to pass through the regular expression.......

//get the value from the textbox 
var _tagObject = document.getElementById('txt_newTag');

//validate the contents  
validateEmail(_tagObject.value,validationExpression);

function validateEmail(stringToValidateArg,validationExpressionArg)
{    
     return validationExpressionArg.test(stringToValidateArg);
}

However this does not work I get the following error message:

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; Tablet PC 2.0)
Timestamp: Tue, 8 Jun 2010 13:44:03 UTC


Message: Object doesn't support this property or method
Line: 101
Char: 5
Code: 0
URI: http://server.com/shared/scripts/tag-list.js

Does anyone know what I cant pass through the regular expression from the html element on the page like I have?

Any help much appreciated pretty new to javascript programming....

Pete

+2  A: 

You don't need quotation marks around the /.../.

onclick="return tagList.addTag(true, /^...$/ )"
#                                   ^       ^ no quotation marks needed.
KennyTM
+1 for first :-)
Andy E
Not only do you not need them, but its a direct error to use them
Sean Kinsey
A: 

You are passing a string, not a regex object. Remove the single quotes around the /.../.

Marcelo Cantos