Results 1 to 3 of 3
  1. #1
    dpkcv is offline Member
    Join Date
    Sep 2011
    Posts
    3
    Rep Power
    0

    Default Regular expression for alphanumeric characters containing space ,"_" and "-"

    1. First word should contain only [0-9a-zA-Z]
    2. Second word can contain any of these characters[0-9a-zA-Z],space,"_" and "-".But same characters(space,"_" and "-") cannot be consicutive.For examples "__","--"," ","_-" are invalid.But "- _" is valid.
    3.
    i) Hello world_-(invalid)
    ii) Hello world_ -(valid)
    iii) Hello world--(invalid)
    iv) Hello world- -(valid)
    v) Hello world_ _(valid)
    vi) Hello world(invalid) - 2 spaces

  2. #2
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    618
    Rep Power
    4

    Default Re: Regular expression for alphanumeric characters containing space ,"_" and "-"

    Can you show your regexp?
    Skype: petrarsentev
    http://TrackStudio.com

  3. #3
    dpkcv is offline Member
    Join Date
    Sep 2011
    Posts
    3
    Rep Power
    0

    Default Re: Regular expression for alphanumeric characters containing space ,"_" and "-"

    Quote Originally Posted by Petr View Post
    Can you show your regexp?
    Java Code:
    	public static boolean isAlphaNumericWithSpace(String input) {	
            return isAlphaNumericWithSpace(input, "_\\-");
        }
        public static boolean isAlphaNumericWithSpace(String input,
                String additionalValidChars) {
    
            /* patternString contains a space */
            String patternString = "([a-zA-Z0-9]+([ ][a-zA-Z0-9])*)+";
    
            if (additionalValidChars != null && additionalValidChars.length() > 0) {
                patternString = "([a-zA-Z0-9]+[ ]?(([" + additionalValidChars
                        + "][a-zA-Z0-9 ])*)?[" + additionalValidChars + "]?)+";
            }
            Pattern pattern = Pattern.compile(patternString);
            return pattern.matcher(input).matches();
        }

Similar Threads

  1. Replies: 0
    Last Post: 06-24-2011, 08:14 PM
  2. Replies: 3
    Last Post: 10-12-2010, 04:21 PM
  3. Replies: 1
    Last Post: 01-21-2010, 09:20 AM
  4. Replies: 2
    Last Post: 01-24-2009, 06:56 PM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 AM

Posting Permissions

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