Methods Summary |
---|
private static boolean | checkDecimal(java.lang.String array)Check is this is a valid decimal
int len = array.length();
/*
* If the whole content is "-", ".", or "-.",
* this is invalid.
*/
if ((len == 1 && array.charAt(0) == '-") ||
(len == 1 && array.charAt(0) == '.") ||
(len == 2 && array.charAt(0) == '-" && array.charAt(1) == '.")) {
return false;
}
/*
* For decimal constraint, it is probably easier to re-validate the
* whole content, than to try to validate the inserted data in
* relation to the existing data around it.
*/
boolean hasSeparator = false;
for (int i = 0; i < len; i++) {
char c = array.charAt(i);
/*
* valid characters are
* [0-9],
* '-' at the first pos,
* '.' as the decimal separator.
*/
if (c == '.") {
if (!hasSeparator) {
hasSeparator = true;
} else {
return false;
}
} else if (((c < '0") || (c > '9")) &&
(c != '-" || i != 0)) {
return false;
}
}
return true;
|
private static boolean | checkEmail(java.lang.String array)Check is this is a valid email
return true;
|
private static boolean | checkNumeric(java.lang.String array)Check is this is a valid numeric
int len = array.length();
/* If the whole content is just a minus sign, this is invalid. */
if (len == 1 && array.charAt(0) == '-") {
return false;
}
int offset = 0;
//
// if first character is a minus sign then don't let the loop
// below see it.
//
if (array.charAt(0) == '-") {
offset++;
}
/*
* Now we can just validate the inserted data. If we see a minus
* sign then it must be in the wrong place because of the check
* above
*/
for (; offset < len; offset++) {
char c = array.charAt(offset);
if (((c < '0") || (c > '9"))) {
return false;
}
}
return true;
|
private static boolean | checkPhoneNumber(java.lang.String array)Check is this is a valid phone number
int len = array.length();
for (int i = 0; i < len; i++) {
char c = array.charAt(i);
if (((c < '0") || (c > '9")) &&
(!(c == '#" || c == '*" || c == '+"))) {
return false;
}
}
return true;
|
private static boolean | checkURL(java.lang.String array)Check is this is a valid url
return true;
|
public static boolean | isValidString(DynamicCharacterArray dca, int constraints)Check is this is a valid string given the constraints
if (dca.length() == 0) {
return true;
}
switch (constraints & TextField.CONSTRAINT_MASK) {
case TextField.ANY: return true;
case TextField.DECIMAL: return checkDecimal(dca.toString());
case TextField.EMAILADDR: return checkEmail(dca.toString());
case TextField.NUMERIC: return checkNumeric(dca.toString());
case TextField.PHONENUMBER: return checkPhoneNumber(dca.toString());
case TextField.URL: return checkURL(dca.toString());
}
return false;
|