Results 1 to 3 of 3
  1. #1
    1111FM is offline Member
    Join Date
    Sep 2008
    Posts
    1
    Rep Power
    0

    Default Java newb Q: 8-digit id

    Hi all, i am struggling to find a way to implement an 8-digit id for a Member class which must begin with 1,2 or 9 in a java program. Appreciate any help in advance.

  2. #2
    racerxadam is offline Member
    Join Date
    Jul 2008
    Posts
    68
    Rep Power
    0

    Default

    Do some reading on Regular Expressions (Java Pattern and Matcher object APIs should help too.) Regular expressions are a very powerful addition to any developer's arsenal.

    Assuming that your ID member is generated somehow you'll want to validate its content as a string against a Pattern to ensure it meets your criteria.

    Example Pattern: $[1|2|9]{1}[0-9]{7}^ The pattern basically says a "match" starts with a single 1,2, or 9 digit character ($[1|2|9]{1}) and ends with 7 digits between 0 and 9 ([0-9]{7}^).

    Note, this may not be exactly the patter you want to use; my regex-foo is a bit rusty.

    Hope this points you in the right direction.
    Last edited by racerxadam; 09-28-2008 at 10:54 PM.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default

    implement an 8-digit id ... must begin with 1,2 or 9
    Please explain. Are you asking for a number with 8 digits that starts with 1,2 or 9? What determines which digit it must start with?
    Random or next in line?
    For example the first would be: 10000000, the next 100000001 etc. to 19999999 and then to 20000000
    Doing them inline like above would keep them unique.

Similar Threads

  1. Newb Topics
    By dkizzy in forum New To Java
    Replies: 2
    Last Post: 09-17-2008, 07:01 AM
  2. convert getValue result in a 4 digit number
    By roseline43 in forum New To Java
    Replies: 0
    Last Post: 09-02-2008, 08:44 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
  •