int 2147483647 limit while checking for phone field

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Sindarin
Forum Regular
Posts: 521
Joined: Tue Sep 25, 2007 8:36 am
Location: Greece

int 2147483647 limit while checking for phone field

Post by Sindarin »

I have a contact form that uses the int function in order to check if a field is complete with numbers,

$phone = (int)$_POST['phone'];

Problem is that the phone number is larger in sum than the int limit which is 2147483647.
Is there any way to check if a field is number or not and is there a function like bigint() or something in php?
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: int 2147483647 limit while checking for phone field

Post by jaoudestudios »

Yep, use the php function is_int()
User avatar
Sindarin
Forum Regular
Posts: 521
Joined: Tue Sep 25, 2007 8:36 am
Location: Greece

Re: int 2147483647 limit while checking for phone field

Post by Sindarin »

Problem is that the phone number can be for example 6943245325 which is over 2147483647. So the max value will be sent instead.
Isn't there another way to do this than storing it to 2 different variables? (one for check and one for send)
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: int 2147483647 limit while checking for phone field

Post by jaoudestudios »

So you are saving it in the database as an INT? You can use BITINT instead.
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: int 2147483647 limit while checking for phone field

Post by Apollo »

Sindarin wrote:Is there any way to check if a field is number or not and is there a function like bigint() or something in php?

Code: Select all

if (!preg_match("/^[0-9]+$/",$phone)) die("phone nr contains non-digits");
Oh, and you should store phone nrs as strings, not numbers. A phone number is merely a unique identification string, its numerical appearance does not reflect any actual numerical properties or meaning.
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: int 2147483647 limit while checking for phone field

Post by jaoudestudios »

True. String would be sufficient as you are not really going to be doing joins on this column.

You might want to strip out white space, someone might do this... 01344 625600
Post Reply