Js regex help plz

guys,

in php i do this regex $pattern = “/[0-9\s]\$/”; to ensure that only numbers are entered with spaces, does anyone know the javascript equivalent pz?

thanks

What problem are you having with that. AFAIK it should work the same. i.e. capture a number or whitespace character appearing before a dollar sign.

var pattern = /^\d+ ?$/;

Though that says the pattern must start with a number.

With regexes it’s better to try to really know specifically what you’re matching.

*edit I misread the $ in the first post. Mittineague caught it.

thanks guys.

:d’oh: I may have seen the escaped literal $ sign, but I should have said “match” not “capture”.

AFAIK javascript pretty much follows PCRE (Perl) syntax, so any problems you may have with PHP regex -> javascript is if you try to use POSIX syntax.