PDA

View Full Version : Please verify a regexp that checks for numeric content only


Jeepers
09-05-2003, 07:27 PM
Hi all
Please forgive me, I'm usless at regular expressions. I've altered one to check that only digits are present, it is positive and an integer, if not zero the variable and it seems to work ok.

unless ($varname =~ /^[+]?(\d+)$/) {$varname=0;}

Can anyone spot a possible problem with the code, would it let other things through that I've not tested for or is there a better way of doing it?

Jeff Mott
09-05-2003, 07:39 PM
It will work fine, though the square brackets and parenthese are unecessary./^\+?\d+$/

Jeepers
09-05-2003, 07:46 PM
Great stuff, and thanks again :thumbsup: