Jump to content


Contains numerical value

  • Please log in to reply
2 replies to this topic

#1 tyrant1337

  • New Members
  • Pip
  • Newbie
  • 2 posts
  • LocationBleakpool

Posted 24 July 2006 - 10:24 AM


Im trying to find out whether a value contains a numerical character in it

i.e. If FY1 1AL then ill do something with it or if its Bleakpool for instance I wont

The code ive found doesnt seem to work

if(preg_match('[0-9]', $value))

Any comments would help


#2 Braet

  • Members
  • PipPip
  • Member
  • 12 posts

Posted 24 July 2006 - 01:13 PM

newb myself, but:

if(ereg("[0-9]", $value))
	{echo "yup";}

echo $value;

does work no matter the number 4 or 473 (and will not return the "yup" if it has no number.  Per php.net, preg_match is usually faster though - I do not know if ereg will suit your needs - but perhaps that will steer you in a direction suited to what you are attempting.

#3 effigy

  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 24 July 2006 - 01:58 PM

PREG needs delimiters; try /\d/.
Regexp | Unicode Article | Letter Database

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users