Skip to content

Commit

Permalink
Added read-only property exposing the parsing error type.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemmermann committed Dec 1, 2023
1 parent e7723be commit 151cf4f
Showing 1 changed file with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dlsc.phonenumberfx;

import com.google.i18n.phonenumbers.AsYouTypeFormatter;
import com.google.i18n.phonenumbers.NumberParseException;
import com.google.i18n.phonenumbers.PhoneNumberUtil;
import com.google.i18n.phonenumbers.Phonenumber;
import javafx.application.Platform;
Expand Down Expand Up @@ -335,7 +336,8 @@ public void set(String newRawPhoneNumber) {
try {
Phonenumber.PhoneNumber number = phoneNumberUtil.parse(newRawPhoneNumber, country.iso2Code());
setPhoneNumber(number);
} catch (Exception e) {
} catch (NumberParseException e) {
errorType.set(e.getErrorType());
setPhoneNumber(null);
}
} else {
Expand All @@ -350,6 +352,25 @@ public void set(String newRawPhoneNumber) {
}
};

// ERROR TYPE

private final ReadOnlyObjectWrapper<NumberParseException.ErrorType> errorType = new ReadOnlyObjectWrapper<>(this, "errorType");

public final NumberParseException.ErrorType getErrorType() {
return errorType.get();
}

/**
* Returns the error type property of the phone number field. The error type
* represents the type of error that occurred during the parsing of the phone
* number.
*
* @return the error type property
*/
public final ReadOnlyObjectProperty<NumberParseException.ErrorType> errorTypeProperty() {
return errorType.getReadOnlyProperty();
}

// RAW PHONE NUMBER

/**
Expand Down Expand Up @@ -454,7 +475,7 @@ private void setE164PhoneNumber(String e164PhoneNumber) {

/**
* @return The phone number parsed out from the {@link #rawPhoneNumberProperty() raw phone number}, this might be {@code null} if the
* phone number is not a valid one.
* phone number is not valid.
*/
public final ReadOnlyObjectProperty<Phonenumber.PhoneNumber> phoneNumberProperty() {
return phoneNumber.getReadOnlyProperty();
Expand Down

0 comments on commit 151cf4f

Please sign in to comment.