checking character problem

Discussion in 'Java' started by James Kilroy, Dec 16, 2003.

  1. James Kilroy

    James Kilroy Guest

    Hello I was wondering if you guys could spot a problem with this code

    I am taking information from a password field and checking to ensure there
    is only letters and digits. It seems to work with errors in JBuilder but
    VisualAge is giving me errors. Any ideas

    String Password=jpassword.getText(); //get password
    int passwordSize=Password.length(); //get length of
    password

    for (int i=0;i<=passwordSize;i++){

    char result=passwordSize.charAt(i);

    if(!Character.isJavaLetterOrDigit(result)) {


    JOptionPane.showMessageDialog(null,"Password can only
    contain letters or digits","Error",
    JOptionPane.WARNING_MESSAGE);

    }
    James Kilroy, Dec 16, 2003
    #1
    1. Advertising

  2. James Kilroy wrote:

    > Hello I was wondering if you guys could spot a problem with this code
    >
    > I am taking information from a password field and checking to ensure there
    > is only letters and digits. It seems to work with errors in JBuilder but
    > VisualAge is giving me errors. Any ideas
    >
    > String Password=jpassword.getText(); //get password
    > int passwordSize=Password.length(); //get length of
    > password
    >
    > for (int i=0;i<=passwordSize;i++){
    >
    > char result=passwordSize.charAt(i);
    >
    > if(!Character.isJavaLetterOrDigit(result)) {
    >
    >
    > JOptionPane.showMessageDialog(null,"Password can only
    > contain letters or digits","Error",
    > JOptionPane.WARNING_MESSAGE);
    >
    > }


    You might want to tell us what errors you are exactly getting.
    Could it be because the isJavaLetterOrDigit method is deprecated? What
    version are you using?

    --
    Kind regards,
    Christophe Vanfleteren
    Christophe Vanfleteren, Dec 16, 2003
    #2
    1. Advertising

  3. "James Kilroy" <> wrote in message
    news:brnnm1$6dr$...
    > Hello I was wondering if you guys could spot a problem with this code
    >
    > I am taking information from a password field and checking to ensure there
    > is only letters and digits. It seems to work with errors in JBuilder but
    > VisualAge is giving me errors. Any ideas
    >
    > String Password=jpassword.getText(); //get password
    > int passwordSize=Password.length(); //get length of
    > password
    >
    > for (int i=0;i<=passwordSize;i++){
    >
    > char result=passwordSize.charAt(i);


    Did it compile?

    Shouldn't it be -

    Password.charAt(i);

    HTH,
    - Manish
    Manish Hatwalne, Dec 16, 2003
    #3
  4. James Kilroy

    James Kilroy Guest

    I am using IBM Visual Age Java 4.0

    yes it is deprecated

    The message I am getting is as follows

    The method charAT invoked for type int with arguments (int) is not defined

    The method isJavaLetterOrDigit invoked for type java.lang.Character with
    arguments (char) is deprecated


    "James Kilroy" <> wrote in message
    news:brnnm1$6dr$...
    > Hello I was wondering if you guys could spot a problem with this code
    >
    > I am taking information from a password field and checking to ensure there
    > is only letters and digits. It seems to work with errors in JBuilder but
    > VisualAge is giving me errors. Any ideas
    >
    > String Password=jpassword.getText(); //get password
    > int passwordSize=Password.length(); //get length of
    > password
    >
    > for (int i=0;i<=passwordSize;i++){
    >
    > char result=passwordSize.charAt(i);
    >
    > if(!Character.isJavaLetterOrDigit(result)) {
    >
    >
    > JOptionPane.showMessageDialog(null,"Password can only
    > contain letters or digits","Error",
    > JOptionPane.WARNING_MESSAGE);
    >
    > }
    >
    >
    James Kilroy, Dec 16, 2003
    #4
  5. James Kilroy wrote:

    > I am using IBM Visual Age Java 4.0
    >
    > yes it is deprecated
    >
    > The message I am getting is as follows
    >
    > The method charAT invoked for type int with arguments (int) is not defined


    That's because you are trying to run that method on an int, like Manish
    pointed out.

    > The method isJavaLetterOrDigit invoked for type java.lang.Character with
    > arguments (char) is deprecated


    That shouldn't prohibit a successfull compilation, but it is best not to use
    deprecated methods.
    Read the api docs at
    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Character.html#isJavaLetterOrDigit(char)


    --
    Kind regards,
    Christophe Vanfleteren
    Christophe Vanfleteren, Dec 16, 2003
    #5
  6. James Kilroy

    Sudsy Guest

    James Kilroy wrote:
    > Hello I was wondering if you guys could spot a problem with this code
    >
    > I am taking information from a password field and checking to ensure there
    > is only letters and digits. It seems to work with errors in JBuilder but
    > VisualAge is giving me errors. Any ideas
    >
    > String Password=jpassword.getText(); //get password
    > int passwordSize=Password.length(); //get length of
    > password
    >
    > for (int i=0;i<=passwordSize;i++){


    Ack! You're rolling off the end of the string! It should be
    i < passwordSize, not i <= passwordSize. If I have a String
    of length 2 then I can only get charAt( 0 ) and charAt( 1 ).
    Sudsy, Dec 16, 2003
    #6
  7. "James Kilroy" <> wrote in message news:<brnnm1$6dr$>...
    > Hello I was wondering if you guys could spot a problem with this code
    >
    > I am taking information from a password field and checking to ensure there
    > is only letters and digits. It seems to work with errors in JBuilder but
    > VisualAge is giving me errors. Any ideas
    >
    > String Password=jpassword.getText(); //get password
    > int passwordSize=Password.length(); //get length of
    > password
    >
    > for (int i=0;i<=passwordSize;i++){
    >
    > char result=passwordSize.charAt(i);


    You didn't mention what the error(s) is(are), but I see one here.
    Your for
    condition shuld be i < passwordSize not i <= passwordSize since
    String.charAt(int) is 0-based.

    Greg
    Gregory A. Swarthout, Dec 16, 2003
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Velvet
    Replies:
    9
    Views:
    14,799
    Joerg Jooss
    Jan 19, 2006
  2. raavi
    Replies:
    2
    Views:
    908
    raavi
    Mar 2, 2006
  3. Ronald Fischer

    checking for supported character set

    Ronald Fischer, Sep 14, 2004, in forum: HTML
    Replies:
    0
    Views:
    327
    Ronald Fischer
    Sep 14, 2004
  4. Daniel

    checking for ASCII character

    Daniel, Nov 13, 2003, in forum: Python
    Replies:
    5
    Views:
    300
    Dan Bishop
    Nov 14, 2003
  5. jalkadir
    Replies:
    5
    Views:
    283
    Default User
    Oct 13, 2005
Loading...

Share This Page