Results 1 to 3 of 3
  1. #1
    009
    009 is offline Member
    Join Date
    May 2014
    Posts
    22
    Rep Power
    0

    Default Pattern matches in java

    hi i have code which validate code enter by user

    the requirement say the maxlength=2 and minlength=1 and is a string

    the user can enter code as follows

    00

    A1

    HH

    12

    10

    09



    I have this code
    Java Code:
    public boolean isValidPattern(String s_value, String s_pattern)
    
        {
    
            boolean flag = false;
    
     
    
            if (Pattern.matches(s_pattern, s_value))
    
            {
    
                flag = true;
    
            }
    
     
    
            return flag;
    
        }
    
     
    
    if (!isValidPattern(code, "[0-9X]{1,2}"))
    
                {
    
               
    
                if(!isValidPattern(code, "[A-Z]{1,2}"))  
    
                  
    
                {
    
                   System.out.println("wrong patten code ");
    
                }


    my problem is when user put

    A1 AM geting error

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    947
    Rep Power
    2

    Default Re: Pattern matches in java

    What about [0-9A-Z]{1,2}
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,049
    Rep Power
    6

    Default Re: Pattern matches in java

    Java Code:
    if (!isValidPattern(code, "[0-9X]{1,2}"))
    Why the X in that pattern? Is there something you're not telling?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Checking a row for sequential matches
    By prog_phil in forum New To Java
    Replies: 3
    Last Post: 01-02-2013, 08:46 PM
  2. Regex: find all possible matches
    By Alessio in forum New To Java
    Replies: 3
    Last Post: 10-19-2010, 01:10 PM
  3. help: matches don`t work
    By asabdo in forum New To Java
    Replies: 6
    Last Post: 01-16-2010, 07:06 AM
  4. How "Pattern.matches(regex, input)" function works?
    By kishan in forum Advanced Java
    Replies: 2
    Last Post: 04-26-2009, 12:46 AM
  5. Help with password matches
    By Albert in forum AWT / Swing
    Replies: 1
    Last Post: 07-10-2007, 04:17 PM

Posting Permissions

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