Jump to content


Photo

regex syntax problem


  • Please log in to reply
1 reply to this topic

#1 robos99

robos99
  • Members
  • PipPipPip
  • Advanced Member
  • 55 posts

Posted 11 June 2006 - 08:57 PM

I've got the following regular expression pattern:
"^[0-9]+$"
to check if a string supplied is a number or not, but i keep getting warnings from php:
Warning: preg_match(): No ending delimiter

I'm kinda confused because isn't the $ the ending delimiter? Maybe I'm missing something.

#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 12 June 2006 - 03:52 AM

The regex should be:
"/^[0-9]+$/" or "/^\d+$/"

You can also use typcasting and convert the value to a number, using (float) $var, (int) var, settype(), and so on

<?php

echo $_GET['d'] . '<br />';
echo (preg_match("/^\d+$/", $_GET['d'])) ? 'true' : 'false';

?>

~ D Kuang




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users