preg_match

Hi

Kindly help on how i can determine that the string contain on numbers


<?php
if(!preg_match('[]','222r')){

}

?>

the condition should return false.

well i’d have assumed it was a typo for “no numbers” :stuck_out_tongue:

Kindly help on how i can determine that the string contain only numbers

var_dump( filter_var('222', FILTER_VALIDATE_INT) );
//returns int 123

var_dump( filter_var('222r', FILTER_VALIDATE_INT) );
//returns false

@lmasi02 do you need to use a regular expression? If not, then [font=monospace]ctype_digit[/font] might be more tailored to what you need.

@Anthony "1234567890
"
(:


<?php
if(1 !== preg_match('~^\\d+$~', '1234567890')){
  #not all numbers
}
?>