Check if String Contains Only Numbers using PHP

preg_match function

<?php

$text = '0210426';
$result = (bool) preg_match('/^\d+$/', $text);

echo $result ? 'Yes' : 'No';

Leave a Comment

Cancel reply

Your email address will not be published.