mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-24 23:18:17 +01:00
Formatting, small cleanups
This commit is contained in:
parent
73c77108b4
commit
8d782ea910
2 changed files with 45 additions and 52 deletions
|
@ -26,8 +26,8 @@ public final class ChaseQuickPayValidator extends InputValidator {
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
public ChaseQuickPayValidator() {
|
public ChaseQuickPayValidator() {
|
||||||
super();
|
super();
|
||||||
emailValidator = new EmailValidator();
|
emailValidator = new EmailValidator();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -35,10 +35,4 @@ public final class ChaseQuickPayValidator extends InputValidator {
|
||||||
return emailValidator.validate(input);
|
return emailValidator.validate(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Private methods
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,43 +44,42 @@ public final class EmailValidator extends InputValidator {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ValidationResult validate(String input) {
|
public ValidationResult validate(String input) {
|
||||||
// TODO
|
if (input == null || input.length() < 6) // shortest address is l@d.cc
|
||||||
if (input == null || input.length() < 6) // shortest address is l@d.cc
|
return invalidAddress;
|
||||||
return invalidAddress;
|
String[] subStrings;
|
||||||
String [] substrings;
|
String local, domain;
|
||||||
String local, domain;
|
|
||||||
|
|
||||||
substrings = input.split("@",-1);
|
subStrings = input.split("@", -1);
|
||||||
|
|
||||||
if (substrings.length == 1) // address does not contain '@'
|
if (subStrings.length == 1) // address does not contain '@'
|
||||||
return invalidAddress;
|
return invalidAddress;
|
||||||
if (substrings.length > 2) // multiple @'s included -> check for valid double quotes
|
if (subStrings.length > 2) // multiple @'s included -> check for valid double quotes
|
||||||
if (!checkForValidQuotes(substrings)) // around @'s -> "..@..@.." and concatenate local part
|
if (!checkForValidQuotes(subStrings)) // around @'s -> "..@..@.." and concatenate local part
|
||||||
return invalidAddress;
|
return invalidAddress;
|
||||||
local = substrings[0];
|
local = subStrings[0];
|
||||||
domain = substrings[substrings.length-1];
|
domain = subStrings[subStrings.length - 1];
|
||||||
|
|
||||||
// local part cannot begin or end with '.'
|
// local part cannot begin or end with '.'
|
||||||
if (local.startsWith(".") || local.endsWith("."))
|
if (local.startsWith(".") || local.endsWith("."))
|
||||||
return invalidAddress;
|
return invalidAddress;
|
||||||
|
|
||||||
String [] splitDomain = domain.split("\\.", -1); // '.' is a regex in java and has to be escaped
|
String[] splitDomain = domain.split("\\.", -1); // '.' is a regex in java and has to be escaped
|
||||||
String tld = splitDomain[splitDomain.length-1];
|
String tld = splitDomain[splitDomain.length - 1];
|
||||||
if (splitDomain.length < 2)
|
if (splitDomain.length < 2)
|
||||||
return invalidAddress;
|
return invalidAddress;
|
||||||
|
|
||||||
if (splitDomain[0] == null || splitDomain[0].isEmpty())
|
if (splitDomain[0] == null || splitDomain[0].isEmpty())
|
||||||
return invalidAddress;
|
return invalidAddress;
|
||||||
|
|
||||||
// TLD length is at least two
|
// TLD length is at least two
|
||||||
if (tld.length() < 2)
|
if (tld.length() < 2)
|
||||||
return invalidAddress;
|
return invalidAddress;
|
||||||
|
|
||||||
// TLD is letters only
|
// TLD is letters only
|
||||||
for (int k=0; k<tld.length(); k++)
|
for (int k = 0; k < tld.length(); k++)
|
||||||
if (!Character.isLetter(tld.charAt(k)))
|
if (!Character.isLetter(tld.charAt(k)))
|
||||||
return invalidAddress;
|
return invalidAddress;
|
||||||
return new ValidationResult(true);
|
return new ValidationResult(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -88,22 +87,22 @@ public final class EmailValidator extends InputValidator {
|
||||||
// Private methods
|
// Private methods
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
private boolean checkForValidQuotes(String [] substrings) {
|
private boolean checkForValidQuotes(String[] subStrings) {
|
||||||
int length = substrings.length - 2; // is index on last substring of local part
|
int length = subStrings.length - 2; // is index on last substring of local part
|
||||||
|
|
||||||
// check for odd number of double quotes before first and after last '@'
|
// check for odd number of double quotes before first and after last '@'
|
||||||
if ( (substrings[0].split("\"",-1).length %2 == 1) || (substrings[length].split("\"",-1).length %2 == 1) )
|
if ((subStrings[0].split("\"", -1).length % 2 == 1) || (subStrings[length].split("\"", -1).length % 2 == 1))
|
||||||
return false;
|
return false;
|
||||||
for (int k=1; k<length; k++) {
|
for (int k = 1; k < length; k++) {
|
||||||
if (substrings[k].split("\"",-1).length % 2 == 0)
|
if (subStrings[k].split("\"", -1).length % 2 == 0)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String patchLocal = new String("");
|
String patchLocal = "";
|
||||||
for (int k=0; k<=length; k++) // remember: length is last index not array length
|
for (int k = 0; k <= length; k++) // remember: length is last index not array length
|
||||||
patchLocal = patchLocal.concat(substrings[k]); // @'s are not reinstalled, since not needed for further checks
|
patchLocal = patchLocal.concat(subStrings[k]); // @'s are not reinstalled, since not needed for further checks
|
||||||
substrings[0] = patchLocal;
|
subStrings[0] = patchLocal;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue