![]() |
|
[PHP] how to check for positive int with is_numeric - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Web Development (https://hackforums.net/forumdisplay.php?fid=183) +---- Thread: [PHP] how to check for positive int with is_numeric (/showthread.php?tid=5814054) |
how to check for positive int with is_numeric - Lockheed - Mar 20, 2018 Basically, im trying to get is_numeric to return true/false, but it needs to only accept positive integers So far it is returning true to positive integers and false to letters however its viewing -5 as an acceptable input. is_int() isn't what im looking for at this stage. i have the following: Cheers PHP Code RE: How to destroy a session and then recreate? - m0noxide - Mar 20, 2018 PHP Code First, you want to make sure that the string there "-5" is numeric If it is, then convert it to an integer so we can properly check it. RE: How to destroy a session and then recreate? - Willful - Mar 20, 2018 Here's what I would recommend trying if you don't decide to do some AJAX approach.
This way after you click onto your homepage, you should check if referrer is not equal to the current uri. If they're not equal, you probably want to destroy the session. PHP Code Hope this might help you move towards the right direction. RE: how to check for positive int with is_numeric - Lockheed - Mar 21, 2018 Alright, im 99% complete i just need help with one last thing. Ive now got is_numeric working however i cant seem to workout how to make a form only appear if is_numeric returns true. Ive put a comment in on the form im trying to achieve this with. Thanks in advanced for your help, appreciate every bit of it. PHP Code RE: how to check for positive int with is_numeric - Nachfolger - Mar 21, 2018 (Mar 21, 2018 05:05 AM)Lockheed Wrote: Alright, im 99% complete i just need help with one last thing.On topic of the -5 returning as an int: A int is not only positive numbers, it's also negative. (−2,147,483,648 to 2,147,483,647) Back to your question, like this: PHP Code PHP Code Edit: Looking at your code, you're doing a lot of weird things. Why are you forcing the type onto $userguess? You should just strip the non-numeric characters, if they put "I42" by accident it will just return 0. Also you're also abusing If statements, you could honestly remove like half of those and combine them. RE: how to check for positive int with is_numeric - .kr. - Mar 21, 2018 you test it in html5 at first Code <input type="number" min="0" step="1" style="display:none;"/>or maybe like Code <input type="number" min="0" step="1" required="required" />RE: how to check for positive int with is_numeric - Nachfolger - Mar 21, 2018 (Mar 21, 2018 05:35 AM).kr. Wrote: you test it in html5 at firstWrong. Relying on input constraints alone is retarded. All anyone would have to do is inspect element and literally remove them. RE: how to check for positive int with is_numeric - Squito - Mar 21, 2018 PHP Code RE: how to check for positive int with is_numeric - .kr. - Mar 22, 2018 @nachfolger i say "first" not only.... with a check in html5 or javascript, the form wont be send for nothing. RE: how to check for positive int with is_numeric - Charger - Mar 23, 2018 (Mar 22, 2018 12:27 PM).kr. Wrote: @nachfolger Right, the same validation that occurs serverside should happen in the frontend as well. |