InteracETransfer

Small fix in EmailValidator
This commit is contained in:
SimonTuberlin 2017-02-09 14:54:03 +01:00
parent d91e83d03f
commit df90eec79e
2 changed files with 46 additions and 2 deletions

View file

@ -59,6 +59,9 @@ public final class EmailValidator extends InputValidator {
local = subStrings[0];
domain = subStrings[subStrings.length - 1];
if (local.isEmpty())
return invalidAddress;
// local part cannot begin or end with '.'
if (local.startsWith(".") || local.endsWith("."))
return invalidAddress;

View file

@ -17,17 +17,41 @@
package io.bitsquare.gui.util.validation;
/*
* Interac e-Transfer requires a mail address or Canadian (mobile) phone number
*
* Mail addresses are covered with class EmailValidator
*
* Phone numbers have 11 digits, expected format is +1 NPA xxx-xxxx
* Plus, spaces and dash might be omitted
* Canadian area codes (NPA) taken from http://www.cnac.ca/canadian_dial_plan/Current_&_Future_Dialling_Plan.pdf
* Valid (as of 2017-06-27) NPAs are hardcoded here
* They are to change in some future (according to the linked document around 2019/2020)
*/
public final class InteracETransferValidator extends InputValidator {
private static final String[] NPAS = {"204", "226", "236", "249", "250", "289", "306", "343", "365", "403", "416", "418", "431", "437", "438", "450", "506", "514", "519", "548", "579", "581", "587", "604", "613", "639", "647", "705", "709", "778", "780", "782", "807", "819", "825", "867", "873", "902", "905"};
private final EmailValidator emailValidator;
///////////////////////////////////////////////////////////////////////////////////////////
// Public methods
///////////////////////////////////////////////////////////////////////////////////////////
public InteracETransferValidator() {
super();
emailValidator = new EmailValidator();
}
@Override
public ValidationResult validate(String input) {
// TODO
return super.validate(input);
if (input == null)
return new ValidationResult(false, "input is null");
ValidationResult emailResult = emailValidator.validate(input);
if (!emailResult.isValid)
return validatePhoneNumber(input);
return emailResult;
}
@ -35,5 +59,22 @@ public final class InteracETransferValidator extends InputValidator {
// Private methods
///////////////////////////////////////////////////////////////////////////////////////////
private ValidationResult validatePhoneNumber(String input) {
// check for correct format and strip +, space and -
if (input.matches("\\+?1 ?\\d\\d\\d ?\\d\\d\\d-?\\d\\d\\d\\d")) {
input = input.replace("+", "");
input = input.replace(" ", "");
input = input.replace("-", "");
String inputAreaCode = input.substring(1, 4);
for (String s : NPAS) {
// check area code agains list and return if valid
if (inputAreaCode.compareTo(s) == 0)
return new ValidationResult(true);
}
} else
return new ValidationResult(false, "Invalid phone number format and not an email address");
return new ValidationResult(false, "Non-Canadian area code");
}
}