After so much Googling, I still did not find any clue/hint to my question, "Is there any way to read character type in PHP?"
So, if you didn't get a clear idea, let's take this variable for example.
$user = $_POST['username'];
// the code checks if the $_POST['username'] has any other type of text other than A-Z a-z or 0-9. If it has, it should echo "error!"
Also is there a way to do this:
$user = $_POST['name'];
// the code checks if the $_POST['name'] has anything other than white spaces, A-Z a-z and dashes, and if it does, it echos "error!"
I hope there is a possibility with PHP as I've seen such things!
You should point your eyes to the ctype_alnum function:
if (!ctype_alnum($user))
echo "error!"
May this two example helps. But the whole reg_exp is a big area with many options! But it's worth to learn it! Tutorial
if(preg_match('^[A-Za-z0-9]+$',$user)==1) /* ok */ else /* not ok */
and
if(preg_match('^[- A-Za-z0-9]+$',$usernmae)==1) /* ok */ else /* not ok */
Use if(preg_match) to know how to use it, use this: http://www.regular-expressions.info/tutorial.html