Results 1 to 6 of 6

Thread: RegEx

  1. #1
    Join Date
    Mar 2010
    Location
    Florida
    Posts
    512
    Thanks
    9
    Thanked 61 Times in 59 Posts

    Default RegEx

    I am trying to make a regex that only allows letters/number/and forward slash
    However there are a few exceptions:
    Before and after the slash can only contain up to 1,9 characters and cannot start or end with a slash.
    EG: 8ajsdl/kjadh which is valid.

    Current regex i am trying is:
    http://jsfiddle.net/2ywpsu5c/
    or
    var patt = /^(([a-zA-Z]{1,9})+([\/]{1}[a-zA-Z]{1,9})+|([a-zA-Z]{1,9}))$/
    Last edited by Deadweight; 10-01-2014 at 10:45 PM.
    -DW [Deadweight]
    Resolving your thread: First Post: => EDIT => Lower right: => GO ADVANCED => Top Advance Editor drop down: => PREFIX:Resolved

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Background/why you want this, is always helpful.

    Also, what problems is it giving you?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Perhaps:

    Code:
    /^(([a-z\d]{1,9})+(\/{1}[a-z\d]{1,9})+|([a-z\d]{1,9}))$/i
    Still, as I say, knowing why you want to do this, as well as what you see as the problem with what you currently have, could help us in answering your question.
    Last edited by jscheuer1; 10-01-2014 at 10:15 AM. Reason: //, []
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #4
    Join Date
    Mar 2010
    Location
    Florida
    Posts
    512
    Thanks
    9
    Thanked 61 Times in 59 Posts

    Default

    Oops sorry i forgot to put what the problem was.
    If i place over 9 characters in the first part (here)/ads it still would be valid.
    -DW [Deadweight]
    Resolving your thread: First Post: => EDIT => Lower right: => GO ADVANCED => Top Advance Editor drop down: => PREFIX:Resolved

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    In that case, how about:

    Code:
    /^(([a-z\d]{1,9})(\/{1}[a-z\d]{1,9})+|([a-z\d]{1,9}))$/i;
    There is a possibility that you may have better results employing 2 or more regular expressions, one to validate the sort of characters, another one or two to validate the number of characters in which positions, perhaps even, logic like:

    if(passes one test){must also pass other test}else{must pass yet another different test}

    if you get my meaning.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. The Following User Says Thank You to jscheuer1 For This Useful Post:

    Deadweight (10-01-2014)

  7. #6
    Join Date
    Mar 2010
    Location
    Florida
    Posts
    512
    Thanks
    9
    Thanked 61 Times in 59 Posts

    Default

    Works great! Thanks:
    For anyone else that wants it:
    http://jsfiddle.net/2ywpsu5c/1/
    -DW [Deadweight]
    Resolving your thread: First Post: => EDIT => Lower right: => GO ADVANCED => Top Advance Editor drop down: => PREFIX:Resolved

Similar Threads

  1. Resolved regex!
    By traq in forum Other
    Replies: 27
    Last Post: 08-18-2010, 02:46 PM
  2. Regex Help
    By fileserverdirect in forum PHP
    Replies: 5
    Last Post: 01-25-2010, 12:35 AM
  3. Regex Help
    By ReadyToLearn in forum PHP
    Replies: 3
    Last Post: 03-24-2008, 03:01 PM
  4. Some Regex Help?
    By alexjewell in forum PHP
    Replies: 5
    Last Post: 10-18-2007, 12:49 AM
  5. regex problem. passing dynamica var in regex
    By s_sameer in forum JavaScript
    Replies: 4
    Last Post: 09-18-2005, 05:01 PM

Bookmarks

Posting Permissions

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