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?
int 2147483647 limit while checking for phone field
Moderator: General Moderators
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: int 2147483647 limit while checking for phone field
Yep, use the php function is_int()
Re: int 2147483647 limit while checking for phone field
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)
Isn't there another way to do this than storing it to 2 different variables? (one for check and one for send)
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: int 2147483647 limit while checking for phone field
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
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");- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: int 2147483647 limit while checking for phone field
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
You might want to strip out white space, someone might do this... 01344 625600