Page 1 of 1
int 2147483647 limit while checking for phone field
Posted: Mon Jan 12, 2009 3:39 am
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?
Re: int 2147483647 limit while checking for phone field
Posted: Mon Jan 12, 2009 3:41 am
by jaoudestudios
Yep, use the php function is_int()
Re: int 2147483647 limit while checking for phone field
Posted: Mon Jan 12, 2009 3:46 am
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)
Re: int 2147483647 limit while checking for phone field
Posted: Mon Jan 12, 2009 4:03 am
by jaoudestudios
So you are saving it in the database as an INT? You can use BITINT instead.
Re: int 2147483647 limit while checking for phone field
Posted: Mon Jan 12, 2009 4:18 am
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.
Re: int 2147483647 limit while checking for phone field
Posted: Mon Jan 12, 2009 4:28 am
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