ctype_xdigit to check hexadecimal characters
$input_string : String to be checked.
ctype_xdigit() is a PHP filter function checks if all chars in the
Hexadecimal is positional numeral system with base of 16. The chars it used are from 0 to 9 and from A to F.
This is a good function to check data coming from insecure sources like user input data. Before storing or processing such data we can use this function check to match our requirement.
Now let us try with some examples.
We can check the form data input by users directly by using ctype_xdigit function. Here is one example.
Removing blank space before usingIt is better to use string function trim to remove blank space present at starting and ending of the variable before using it. Users some time add blank space and this goes wrongly as not alphanumeric variable. Here is the modified script to remove blank space.
For easy understanding here is the form to submit data to above script
DEMOHere if you want to check only numeric numbers then better to use is_numeric() function.
Subscribe to our YouTube Channel here
This article is written by plus2net.com team. https://www.plus2net.com
|▼ Web Forms & handling data in PHP|