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.

Printable View

- 09-28-2008, 07:20 PM1111FMJava 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.

- 09-28-2008, 10:49 PMracerxadam
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. - 09-29-2008, 02:37 PMNormQuote:

implement an 8-digit id ... must begin with 1,2 or 9

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.