sudhakararaog Posted May 14, 2008 Share Posted May 14, 2008 hi i need to validate a field in a form where a user enters their lodgement number as part of a registration form. this lodgement number can have letters, numbers, spaces and special characters. i do not know exactly what those special characters are, so do i have to define the type of special characters and validate accordingly. presently my php code for validating the lodgement number is $lodgementtf = $_POST["lodgementtf"]; if($lodgementtf == "" || !preg_match("/^[a-zA-Z0-9_ <]+$/", $lodgementtf) ) { echo "display error message": } i also have another way of validating if($lodgementnumber == "" || !preg_match("/^[a-zA-Z0-9_ !-@£$%^&*()]+$/", $lodgementnumber) ) does this mean that the special characters can only be = a space AND _!-@£$%^&*() and no other special characters. please advice. thanks. Link to comment https://forums.phpfreaks.com/topic/105542-form-validation-using-php/ Share on other sites More sharing options...
haku Posted May 14, 2008 Share Posted May 14, 2008 I'm an amateur when it comes to regex, but I have a basic understanding of it. And I believe that yes, only those characters are permitted. I think you don't need the leading or trailing forward slashes ('/') in your expressions. Link to comment https://forums.phpfreaks.com/topic/105542-form-validation-using-php/#findComment-540665 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.