Jump to content

only accept numbers


shirvo

Recommended Posts

i dont know about is_numeric()
but i can help you with "^[0-9]*"
[code]
<?php
$phone = $_POST['phone_no'];//where it gets the phone no. from the form.
$regex ="^[0-9]*";//this is where it checks if it is all numbers
if(!eregi($regex,$phone)){echo "your phone number is not in numbers, ie. are you from mars??";}
?>
[/code]
got it?
i havnt try it myself... so it might not work.
Ted
Link to comment
https://forums.phpfreaks.com/topic/30953-only-accept-numbers/#findComment-142885
Share on other sites

PCRE > POSIX regex :)


eg,

[code]$phone = $_POST['phone_no'];//where it gets the phone no. from the form.
if(preg_match('/\d+/', $phone) == 0)
echo "your phone number is not in numbers, ie. are you from mars??";[/code]

Alternativly, use is_int or is_numeric...
Link to comment
https://forums.phpfreaks.com/topic/30953-only-accept-numbers/#findComment-142889
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.