Results 1 to 3 of 3
  1. #1
    captainpirate is offline Member
    Join Date
    May 2011
    Posts
    10
    Rep Power
    0

    Default userName/password Regular Expression

    I have made a swing that takes userName/password as input.
    I'm totally newbie to regular expression.
    What i want is the regular expression for userName is
    - between 5-30 character
    - may contain letter
    - may be alphanumeric
    - may contain _ or . or both or starting letter may be number or letter.
    - doesnt start with number or _ or .
    - disallow any other special character or symbol.

    And Password must be :
    - between 6-30
    - may be alphanumeric
    - must contain at least one numeric digit
    - may contain _ or . @ or # or ! or - or all.
    Help me.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: userName/password Regular Expression

    I wouldn't use a regular expression.

    I'm not saying it can't be done with a regular expression. But regular expressions are even more complicated than your password requirements! ;) I'd be looking at String and Character methods to see if they couldn't be pressed into service.

  3. #3
    captainpirate is offline Member
    Join Date
    May 2011
    Posts
    10
    Rep Power
    0

    Default Re: userName/password Regular Expression

    Sorry for the late reply.
    I have use Regex library as:
    For userName:

    public static boolean isUserNameValid(String name) {
    boolean isValid = false;
    String expression = "^[a-zA-Z0-9.-]{5,30}$";
    CharSequence inputStr = name;
    Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(inputStr);
    if (matcher.matches()) {
    isValid = true;
    }
    return isValid;
    }

    For Password :
    String expression = "((?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{6,30})";

    Thanks @pbrockway2 for the reply.

Similar Threads

  1. Username And Password
    By razmyasdfg in forum JDBC
    Replies: 9
    Last Post: 05-18-2011, 02:59 PM
  2. New to GUI. Logging in with Password and username
    By slitka in forum New To Java
    Replies: 3
    Last Post: 04-11-2011, 11:39 PM
  3. Encrypt Password and Username
    By hardcorebadger in forum New To Java
    Replies: 5
    Last Post: 01-26-2011, 03:47 PM
  4. password username and databases
    By chalo in forum JCreator
    Replies: 0
    Last Post: 12-02-2008, 08:11 AM
  5. Help, created a username and password box
    By cachi in forum AWT / Swing
    Replies: 1
    Last Post: 08-07-2007, 04:21 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
  •