Java Reference
In-Depth Information
\\(? ( \\d{3} ) \\)? [-. ]? ( \\d{3} ) [-. ]? ( \\d{4}
)
Grouping
Figure 5.4: Using grouping in a regular expression
properties, and Stripes will automatically use the phone number type
converter. We can still override the default for a given property by using
the converter= attribute.
Implementing a Formatter
With a type converter for the PhoneNumber data type, we're halfway
there. Let's implement a formatter, with two format types:
"dashes" : NNN-NNN-NNNN
"parens" : (NNN) NNN-NNNN
With a default value for the format type (say, "dashes" ), the formatType=
attribute will be optional. The formatPattern= attribute will not be used.
Here is the resulting PhoneNumberFormatter :
Download email_07/src/stripesbook/ext/PhoneNumberFormatter.java
package stripesbook.ext;
public class PhoneNumberFormatter implements Formatter<PhoneNumber> {
private String formatType = "dashes";
public void setFormatType(String formatType) {
this .formatType = formatType;
}
public void setLocale(Locale locale) { }
public void setFormatPattern(String formatPattern) { }
public void init() { }
public String format(PhoneNumber phoneNumber) {
String format = null ;
if ("dashes".equalsIgnoreCase(formatType)) {
format = "%s-%s-%s";
}
 
 
Search WWH ::




Custom Search