PDA

View Full Version : Validation allow question



sonny
Oct 11th, 2011, 05:06 PM
Hi I am trying to validate to allow just letters, numbers, @ dot and spaces only,
but block everything else, but when a symbol is entered using the syntax below,
it lets the form submit anyway but with no content.



if(preg_match("/^[a-zA-Z0-9 @ . , \"\']+$/", $_POST["message"]) === 0)


This works but does not allow @ period or spaces


if(ereg('[^A-Za-z0-9]', $_POST['message']))


Thanks
Sonny

MarPlo
Oct 11th, 2011, 05:43 PM
Hi,
Try this code:

if(preg_match("/^[a-zA-Z0-9,'\.\"@]+$/", $_POST["message"]))

sonny
Oct 11th, 2011, 06:12 PM
Hi,
Try this code:

if(preg_match("/^[a-zA-Z0-9,'\.\"@]+$/", $_POST["message"]))

That syntax lets < and $ pass, just like the other one I posted

Thanks
Sonny