View Full Version : regex to prevent x0 insertions

03-09-2010, 07:18 AM

I thought I had this wokring but it seems not. Was trying to enter the word 'exceptional' but it was rejected, likely due to the x. It's the only thing I can think of.

So here is my regex. How can the /x0/ part be improved.

if ( $title =~ /^[^\w\d\s\ \'\!\?\\$\&\(\)\-\+\;\:\@\,\.]+$/ || $title =~ /[x0]/ || $title eq '' ) {


03-09-2010, 02:47 PM
What makes you think it was rejected due to the x?

Why are you needlessly escaping all those characters in the character class?

What was the exact error message when it was rejected?

Please post a more complete section of the related code?

03-09-2010, 06:52 PM
I'll give a better reply later but, the reason I thought it was the x was because; when I removed this from the conditional

$title =~ /[x0]/

The script didn't baulk and instead worked fine. There was no '0' (zero) in the string so I assumed it was the 'x'.

I'll tidy it up and see if that helps.