[thelist] numeric only regex?

Christian Heilmann codepo8 at gmail.com
Tue Aug 2 15:51:41 CDT 2005


On 8/2/05, Tom Dell'Aringa <pixelmech at yahoo.com> wrote:
> Hi, I'm trying to come up with a simple regex that will allow me to test for numbers 0-9 ONLY. The
> numbers are held in a variable 'numtext'. I got as far as:
> 
> var match = /[\d\d]/.test(numtext);
> 
> But this is not working. Can someone help out, regex is not my thang..thanks.

Try var match=/^[0-9]$/.test(numtext);

this checks for 1 digit in the range 0-9 inclusive.


-- 
Chris Heilmann 
Blog: http://www.wait-till-i.com
Writing: http://icant.co.uk/  
Binaries: http://www.onlinetools.org/


More information about the thelist mailing list