Jump to content


Photo

Contains numerical value


  • Please log in to reply
2 replies to this topic

#1 tyrant1337

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

Posted 24 July 2006 - 10:24 AM

Hi,

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

Cheers

#2 Braet

Braet
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 24 July 2006 - 01:13 PM

newb myself, but:

<?php
$value="473";
if(ereg("[0-9]", $value))
	{echo "yup";}

echo $value;
die();
?>

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

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
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users