I have a simple php mailer script that I've been using. It's been pretty good at blocking spam posts, but I'm getting more and more spam. So I need another line of code or 2 to block letters and only allow Numbers + this character "-" for the Phone number input. Currently, I have these lines of code blocking other forms of form spam: if(strpos($_POST['comments'], 'http://') !== false) die(); if(strpos($_POST['comments'], '<a') !== false) die(); if(strpos($_POST['phone'], 'http://') !== false) die(); if(strpos($_POST['phone'], '<a') !== false) die(); So this needs to be able to submit: 555-555-5555; But if it contains any letter, it needs to die. I appreciate any help. If it gets too complex, I'm not opposed to paying someone. Thanks!
Or you can use the php build in function is_numeric : if(!is_numeric($something))die('Not Numeric'); Code (markup):
The problem with is_numeric() is that 0X0046ffcc or 2.43578365+E18 are valid numbers as well. Sometimes you dont want that. In that scenario preg_match is the best way to go..