SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2009
    Posts
    152
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    regularexpression dought

    can any body help out a regular expression which is case sensitive ,and can enter _,- and numbers also but no space should contain in stead of this no other symbols or any other thing also can anbody pls

  2. #2
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,396
    Mentioned
    54 Post(s)
    Tagged
    0 Thread(s)
    Your post is not clear but do you need to allow alphanumeric characters (the English alphabet: a, b, c ... z; and digits: 0, 1, 2 ... 9) and the underscore (_), comma (,) and hyphen (-) characters?

    Depending on what you want precisely, a regular expression will be different. Do you want to validate a string to make sure it only contains those characters; to filter it to remove anything which is not those characters; or to match sequences of those characters?
    Salathe
    Software Developer and PHP Manual Author.

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2009
    Posts
    152
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your post is not clear but do you need to allow alphanumeric characters (the English alphabet: a, b, c ... z; and digits: 0, 1, 2 ... 9) and the underscore (_), comma (,) and hyphen (-) characters?

    i need to allow only this much this in my text field pls give an expression which works nicely and"it should not allow space"

  4. #4
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,396
    Mentioned
    54 Post(s)
    Tagged
    0 Thread(s)
    Do you need to make an error if there are "invalid" characters, or do you just need to filter out the characters that you do not want? Your first post also asks for the regular expression to be "case sensitive". Do you only want to match uppercase (A, B, C) or lowercase (a, b, c)? Or did you really mean "case insensitive" meaning you want to allow upper- and lowercase letters?

    For an example, if you simply wanted your characters to be lowercase (and those others you want) you could use:
    PHP Code:
    $filtered preg_replace('/[^a-z0-9_,-]+/'''$string); 
    Salathe
    Software Developer and PHP Manual Author.

  5. #5
    SitePoint Zealot
    Join Date
    Jul 2009
    Posts
    152
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    only the lower case letters and i need it to validate.really i am using it for my username feild where they can use characters which is in between a-z and _,-and 0-9 numbers where the space should not take place and not any other symbols


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
  •