I am using preg_match for restrict the special characters in form post. Now I need to restrict some special characters only like %,$,#,* and I need to post like bé. How to possible to restrict some special characters only.
My code:
<?php $firstname=''; if(isset($_POST['submit'])) { $firstname=$_POST['firstname']; if(preg_match("/[^a-zA-Z0-9]+/", $firstname)) { echo 'Invalid Name'; } else { echo $firstname; } } ?> <html> <body> <form method="post"> <input type="text" name="firstname"/> <input type="submit" name="submit" value="Submit"/> </form> </body> </html>
-as a character in firstnames.... haven't you every heard ofJean-Claude Van Damme? Though I can't think of any first names that contain numbers off the top of my head