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
    New Coder
    Join Date
    Feb 2007
    Posts
    78
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Question Regular expression

    I want regular expression which allows only alphanumeric values including -,_,/,\
    all other special characters are not allowed.

    Thanks in advance,
    Prajwala

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    try this
    Code:
    /[a-z0-9_/\-]+/i
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,310
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    /^[a-z0-9_\/\\\-]+$/i

    or

    /^[\w\/\\\-]+$/

    The \ and / characters must be escaped with a \ to cause them to be interpreted as literals. I usually escape the hyphen - as well.
    \w is equivalent to a-zA-Z0-9_

    Note the ^ and $ characters - these define the start and end of the string to be tested. If they are not included then anything containing (one or more of) the permitted characters (something like £ab&c or x£yz%) will return true.

    What is wanted is to permit a-Z0-9_\/- and nothing but.
    Last edited by Philip M; 05-18-2007 at 06:39 PM. Reason: Add comment re ^ and $


  •  

    Posting Permissions

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