Home > Backend Development > PHP Problem > PHP detects whether the text box is a number

PHP detects whether the text box is a number

王林
Release: 2023-02-25 06:08:02
Original
2556 people have browsed it

PHP detects whether the text box is a number

PHP is_numeric detects whether the variable is a number or a numeric string

Format: bool is_numeric (mixed $var)

If var is a number or numeric string, return TRUE, otherwise return FALSE.

For example 1:

<?php
    $v = is_numeric (&#39;58635272821786587286382824657568871098287278276543219876543&#39;) ? true : false;
    
    var_dump ($v);
?>

The above script will output:

bool(true)
Copy after login

For example 2:

<?php
$str="0";
$strTest=is_numeric(0);
var_dump($strTest);
?>
boolean true
Copy after login

Extension:

is_bool();//Determine whether it is a Boolean type

is_float(); //Determine whether it is a floating point type

is_int(); //Determine whether it is an integer type

is_numeric(); //Determine whether it is a numeric type

is_string(); //Judge whether it is a string

is_array(); //Judge whether it is an array

is_object(); //Judge whether it is an object

Recommended tutorial: PHP video tutorial

The above is the detailed content of PHP detects whether the text box is a number. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template