Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

A maximum of 10(1-10) digits, and a maximum of 2(0-2) white space

Last post 06-29-2009, 7:40 PM by Aussie Susan. 1 replies.
Sort Posts: Previous Next
  •  06-29-2009, 10:15 AM 54419

    A maximum of 10(1-10) digits, and a maximum of 2(0-2) white space

    what can be the regular expression for the condition .

    That a input  should contain a maximum of 10(0 to 10)digits, and a maximum of 2 (0 to 2)white space .

    no other charectes should be allowed.

    The white space may come at any position. even white space may not come.

     :(

     

     

     

  •  06-29-2009, 7:40 PM 54433 in reply to 54419

    Re: A maximum of 10(1-10) digits, and a maximum of 2(0-2) white space

    Can you please read the posting guidelines in the sticky note at the beginning of this forum as you have not really given us enough information to help you.

    I'm guessing that you are using a regex variant that allows for variable length lookaheads and does not have line terminator characters at the end of the string. Also I'm assuming that you are looking at a single line string.

    Try:

    ^(?!(.*?[ \t]){3})(?!(.*?\d){11})[ \t\d]*$

    The '^' and '$' force the whole string to be matched as they anchor the start to the beginning of the input string and the end of the match to the end of the string.

    The first lookahead will fail if there are 3 space or tab characters within the string anywhere. By the way, you might be able to substitute '\s' for the '[ \t]' character class definition which will widen the range of whitespace characters but will also include the line terminators.

    The next lookahead does the same thing an will fail if there are 11 digits anywhere in the string.

    The main character set definition allows there to be 0 or more characters made up from a combination of the characters previously tested. In this case we don't need to check the number as this has already been taken care of by the 2 lookaheads, but we do need to check the characters.

    This pattern WILL match a blank string, but that meets the requirements of your text, but not your posting title. If the posting title is correct, then change the '*' on the last character set to '+'.

    Susan 

View as RSS news feed in XML