Hello I have the following preg_match: if (preg_match('~^[^0-9]~', $id)) { echo "<script>alert('no match found.')</script>"; PHP: It is searching an ID which is made up of numbers like 84773 The problem is, the preg_match still allows 84773+347.3253 for example. How do I make it only accept numbers like 23 and 39583?
Thank you for the reply. '~^\d+$~' PHP: This seems to still allow periods and + signs. I tried: if (!ctype_digit($id)) { echo "<script>alert('no match found.')</script>"; Code (markup): Which gave an alert for an all number ID
Any one else have any ideas? I'm trying to give an alert if the ID is anything but a number like 83485 or 344 or 2. No periods, hyphens, plus signs or spaces, etc. Thanks!
I tried with ctype_digit and it worked just fine, you could try is_numeric: if (!is_numeric($id)) { echo "<script>alert('no match found.')</script>"; } PHP:
Good point, @readezarchive ctype_digit() is probably the best way to go, you should reassign the best answer to nico_swd for post#2.
I tested (!is_numeric($id) Code (markup): out with 34243x3434, 33423xffff and it worked correctly. Are you sure? The Url with the ID it's checking is like google.com/test.php?id=23435 It's checking the ID to make sure it's all numbers with no space, letters or extra characters.