I just want to know the method to check a PHP variable for any non-numbers and if it also detects spaces between characters? Need to make sure nothing weird gets put into my form fields. Thanks in advance.
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- how to split a list into a given number of sub-lis
- Can php detect if javascript is on or not?
This will return
true
if there are non-numbers in the string. It detects letters, spaces, tabs, new lines, whatever isn't numbers.You can use
is_numeric()
:This will check that the value is numerical, so it may contain something else than digits:
But this will ensure that the value is a valid number.
Cast and compare:
You can use
ctype_digit
eg:
This will check whether the input value is numeric or not. Hope this helps