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
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.
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.
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?Quote:
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.