Results 1 to 4 of 4
  1. #1
    GTM
    GTM is offline Member
    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0

    Post 4 digit restriction

    Hey guys, I'm new at the forum, hope I'm not doing nothing wrong.
    I have this problem, when I tipe in the PIN (that as to be 4 digits) if the 1st digit isn't a zero it's all good, but if is not it asumes that is a shorter number (like: 0321 it assumes that the number tipped in is 321 and dosen't pass in my 4 digit restriction).
    I would like to know if some one can help me with this.
    thnks
    GTM

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  3. #3
    JavaHater is offline Senior Member
    Join Date
    Dec 2010
    Posts
    165
    Rep Power
    4

    Default

    Quote Originally Posted by GTM View Post
    Hey guys, I'm new at the forum, hope I'm not doing nothing wrong.
    I have this problem, when I tipe in the PIN (that as to be 4 digits) if the 1st digit isn't a zero it's all good, but if is not it asumes that is a shorter number (like: 0321 it assumes that the number tipped in is 321 and dosen't pass in my 4 digit restriction).
    I would like to know if some one can help me with this.
    thnks
    GTM
    treat the input pin as a string first, check using the string length() method for 4 digits. ( i am sure you know how).
    You are not doing any maths on the PIN right? If that's the case, use it as a string. There's no need to declare it as integers (or longs)

  4. #4
    GTM
    GTM is offline Member
    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0

    Default

    Hey guys, I already did that, but my Input as to be a short, cuse this is a school project and they use a class to test ower classes and in that class they only input shorts as pin, so my code to validate PIN is:

    Java Code:
    public short validarPin(String pinS) {
            if (pinS.length() !=4) {
                return 0;
            }
            for (int i = 0; i < pinS.length(); i++) {
                Character a = pinS.charAt(i);
                if (!a.isDigit(a)) {
                    return 0;
                }
            }
            return (short) Integer.parseInt(pinS);
        }

Similar Threads

  1. eclipse , Access restriction
    By miko5054 in forum Eclipse
    Replies: 7
    Last Post: 07-17-2010, 03:52 PM
  2. Access Restriction error
    By kraut in forum New To Java
    Replies: 2
    Last Post: 06-19-2010, 02:29 AM
  3. Access Restriction error
    By kraut in forum Eclipse
    Replies: 0
    Last Post: 06-19-2010, 02:07 AM
  4. Replies: 7
    Last Post: 02-19-2010, 12:03 PM
  5. Can we lift the images restriction?
    By Cyorxamp in forum Suggestions & Feedback
    Replies: 30
    Last Post: 07-01-2008, 09:32 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
  •