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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Feb 2007
    Posts
    217
    Thanks
    25
    Thanked 1 Time in 1 Post

    Question error in my regex

    I want to check if a certain variable (title) contains alphabetic, numeric or strange characters like etc.

    I've got this coding so far.. but there is an error in it: Parse error: syntax error, unexpected T_STRING

    Probally I'm missing an escape somewhere..

    Also In the coding I have so far I'm missing the check for numbers.



    PHP Code:
    if ((utf8_strlen($this->request->post['title']) < 1) || (utf8_strlen($this->request->post['title']) > 64 || preg_match('/^[a-zA-Z\-_ '???????????????????A??EHI?LOS?T?TUUY??a?d?ehi?los?t?tuuy??AAA?A???CCCCD??EEEEE????GGGGG?aaa?a???ccccd?d?eeeee????ggggg?H?HIIIIIII??JK?LLLL?'NNNNN?OOOO??Oh?hiiiiiii??jk??llll??nnnn?oooo??oRRRSSS???TT?TUUUUUUU?U??W???Y???ZZ?rrr?sss??tt?tuuuuuuu?u??w???y???zz?]$/i'$this->request->post['title']))) { 

    Can someone help me out with adding numbers and getting rid of the error ?

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,460
    Thanks
    0
    Thanked 632 Times in 622 Posts
    The colour change basically shows you where the unescaped ' is close to the front of the preg_match where it goes from ref to blue.

    To include numbers as well simply change a-zA-Z to a-zA-Z0-9
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    Regular Coder
    Join Date
    Feb 2007
    Posts
    217
    Thanks
    25
    Thanked 1 Time in 1 Post
    Thanks, how exactly can I escape this ' character?

    Putting an backslash in front of it doesn't help since it is in the middle of the preg_match.

  • #4
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    709
    Thanks
    20
    Thanked 84 Times in 84 Posts
    preg_match('/^[a-zA-Z\-_ ’(\')‘
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only59 / month


  •  

    Posting Permissions

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