Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get length of integers in PHP ?

Tags:

php

integer

I want to get the length of integer values for validation in PHP. Example: Mobile numbers should be only 10 integer values. It should not be more than 10 or less than 10 and also it should not be included of alphabetic characters.

How can I validate this?

like image 372
GitsD Avatar asked Oct 22 '10 15:10

GitsD


People also ask

How do I find the length of an integer in PHP?

filter_var($int, FILTER_VALIDATE_INT)) { echo "Only integer values are required!"; exit(); } else { // Convert the integer to array $int_array = array_map('intval', str_split($int)); //get the lenght of the array $int_lenght = count($int_array); } //Check to make sure the lenght of the int does not exceed or less ...

How do you find the length of an integer?

Using Continuous Multiplication We can multiply a number 1 by 10 until it becomes greater than the number n. Each time we multiply by 10, we increment a variable count by 1. The final value of the count gives the length of the integer n.

What is the limit of PHP integer value?

PHP Integers An integer data type is a non-decimal number between -2147483648 and 2147483647 in 32 bit systems, and between -9223372036854775808 and 9223372036854775807 in 64 bit systems. A value greater (or lower) than this, will be stored as float, because it exceeds the limit of an integer.

Is an integer PHP?

The is_int() function checks whether a variable is of type integer or not. This function returns true (1) if the variable is of type integer, otherwise it returns false.


1 Answers

$num_length = strlen((string)$num); if($num_length == 10) {     // Pass } else {     // Fail } 
like image 52
mdm Avatar answered Oct 13 '22 09:10

mdm