Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts

    regex to prevent x0 insertions

    Hi,

    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.

    Code:
      if ( $title =~ /^[^\w\d\s\ \'\!\?\\$\&\(\)\-\+\;\:\@\,\.]+$/ || $title =~ /[x0]/ || $title eq '' ) {
    bazz
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link

  • #2
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,835
    Thanks
    2
    Thanked 158 Times in 153 Posts
    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?

  • #3
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    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

    Code:
    $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.


    bazz
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •