Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JScript error in JavaScript code 1

Status
Not open for further replies.

Peppi

Programmer
Apr 9, 2001
205
CA
Hi,

I'm adding some JavaScript code to my ASP.NET page. Here's my JavaScript function as it appears in the web page source:

<script language='JavaScript' type='text/javascript'>
function isNumeric(x) {
var RegExp = /^(-)?(\d*)(\.?)(\d*)$/;
var result = x.match(RegExp);
return result;}
</script>

This bombs on the x.match(RegExp) line. I receive the following error:

Microsoft JScript runtime error: Object doesn't support this property or method

It can't find the 'match' function I guess, but why am I receiving a JScript error when my code is in JavaScript? I'm assuming that's why it can't find it. I've tried specifying just the language tag and just the type tag, but it doesn't eliminate the error.

Any help is appreciated.
 
[1] You probably pass a number (eg 12.5) rather than a numeric string (eg "12.5") to the function. To accommodate this, change this line.
>var result = x.match(RegExp);
[tt]var result = x.toString().match(RegExp);[/tt]

[2] Name the variable RegExp is awkward, although it works here. But you may not like be told to change it to something else. It's up to you.
 
Thanks! toString() worked and I renamed the variable.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top