Jump to content

[SOLVED] Only allow numbers in form


aQ

Recommended Posts

If you want to delete all of the non-numeric chars, use:

$only_nums = preg_replace("/[^0-9]/", "", $string);

 

If you only want to validate the string is numeric I'd use:

<?php
if(!is_numeric($num) || !preg_match("/^[0-9]+$/", $num))
{
//Invalid
}else{
//Valid
}
?>

 

Orio.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.