Java Reference
In-Depth Information
// code may, optionally, be surrounded by
parentheses. If an area code is included,
// the number may optionally be prefixed by a '1'
for long distance numbers.
// Optional hyphens my appear after the country
code (1), the area code, and the
// first 3 digits of the 7 digit number.
//
@Override
public boolean validate(String fieldValue) {
return Pattern.matches("^1?[-
]?\\(?(\\d{3})\\)?[- ]?(\\d{3})[- ]?(\\d{4})$",
fieldValue);
}
},
SOCIAL_SECURITY_NUMBER("ssn") {
// A social security number must contain 9 digits
with optional hyphens after the
// third and fifth digits.
//
@Override
public boolean validate(String fieldValue) {
return Pattern.matches("^\\d{3}[- ]?\\d{2}[-
]?\\d{4}$",
fieldValue);
}
}; // End of enum constants definition
// Instance members
//
private String fieldName;
private FieldType(String fieldName) {
this.fieldName = fieldName;
}
Search WWH ::




Custom Search