Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

eregi

Status
Not open for further replies.

SPYDERIX

Technical User
Jan 11, 2002
1,899
CA
I have been out of the programming game for a while now and I've tried to implement an old script I created but now have an error saying the eregi() function was removed and it throws an error. How would I re-write this now:

Code:
if (empty ($_POST["var"]) || !eregi ("^[0-9]+$", $_POST["var"]))
[indent]{
// validation failed
}[/indent]

I tried this with preg_match but it's no bueno. Need to check if the string is a number basically:

Code:
$str = "7856";
$pattern = "^[0-9]+$";

if (preg_match($pattern, $str))
	{
    echo 'val passed';
    }
else
	{
    echo 'val failed - string is not a number';
    }

NATE
 
Hi

PCRE must have delimiters. The most frequent ones used to be [tt]/[/tt] .. [tt]/[/tt] :
PHP:
[b]if[/b] [teal]([/teal][b]empty[/b] [teal]([/teal][navy]$_POST[/navy][teal][[/teal][i][green]"var"[/green][/i][teal]]) || ![/teal][COLOR=orange]preg_match[/color][teal]([/teal][i][green]'[highlight]/[/highlight]^[0-9]+$[highlight]/[/highlight]'[/green][/i][teal],[/teal] [navy]$_POST[/navy][teal][[/teal][i][green]"var"[/green][/i][teal]]))[/teal]
[teal]{[/teal]
    [gray]// validation failed[/gray]
[teal]}[/teal]
( Note that [tt]$[/tt] and other characters have special meaning when used in double quoted ( [tt]"[/tt] .. [tt]"[/tt] ) strings, so unless you need variable expansion, is better to use single quoted ( [tt]'[/tt] .. [tt]'[/tt] ) strings for regular expressions. )

Feherke.
feherke.github.io
 
Ok cool. Thanks. I honestly have never fully grasped REGEX. It seems complicated to me

NATE
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top