Methods Summary |
---|
public static boolean | isValidDate(java.lang.String dateString, java.lang.String dateFormatPattern)Returns true if the specified date string represents a valid
date in the specified format.
Date validDate = null;
synchronized (dateFormat) {
try {
dateFormat.applyPattern(dateFormatPattern);
dateFormat.setLenient(false);
validDate = dateFormat.parse(dateString);
}
catch (ParseException e) {
// Ignore and return null
}
}
return validDate != null;
|
public static boolean | isValidEmailAddr(java.lang.String emailAddrString)Returns true if the email string contains an at sign ("@") and
at least one dot ("."), i.e. "hans@gefionsoftware.com" is accepted
but "hans@gefionsoftware" is not. Note! This rule is not always
correct (e.g. on an intranet it may be okay with just a name) and
does not gurantee a valid Internet email address but it takes
care of the most obvious Internet mail address format errors.
boolean isValid = false;
if (emailAddrString != null &&
emailAddrString.indexOf("@") != -1 &&
emailAddrString.indexOf(".") != -1) {
isValid = true;
}
return isValid;
|
public static boolean | isValidInteger(java.lang.String numberString, int min, int max)Returns true if the specified number string represents a valid
integer in the specified range.
Integer validInteger = null;
try {
Number aNumber = numberFormat.parse(numberString);
int anInt = aNumber.intValue();
if (anInt >= min && anInt <= max) {
validInteger = new Integer(anInt);
}
}
catch (ParseException e) {
// Ignore and return null
}
return validInteger != null;
|
public static boolean | isValidString(java.lang.String value, java.lang.String[] validStrings, boolean ignoreCase)Returns true if the specified string matches a string in the set
of provided valid strings, ignoring case if specified.
boolean isValid = false;
for (int i = 0; validStrings != null && i < validStrings.length; i++) {
if (ignoreCase) {
if (validStrings[i].equalsIgnoreCase(value)) {
isValid = true;
break;
}
}
else {
if (validStrings[i].equals(value)) {
isValid = true;
break;
}
}
}
return isValid;
|
public static java.lang.String | replaceInString(java.lang.String in, java.lang.String from, java.lang.String to)Replaces one string with another throughout a source string.
if (in == null || from == null || to == null) {
return in;
}
StringBuffer newValue = new StringBuffer();
char[] inChars = in.toCharArray();
int inLen = inChars.length;
char[] fromChars = from.toCharArray();
int fromLen = fromChars.length;
for (int i = 0; i < inLen; i++) {
if (inChars[i] == fromChars[0] && (i + fromLen) <= inLen) {
boolean isEqual = true;
for (int j = 1; j < fromLen; j++) {
if (inChars[i + j] != fromChars[j]) {
isEqual = false;
break;
}
}
if (isEqual) {
newValue.append(to);
i += fromLen - 1;
}
else {
newValue.append(inChars[i]);
}
}
else {
newValue.append(inChars[i]);
}
}
return newValue.toString();
|
public static java.util.Date | toDate(java.lang.String dateString, java.lang.String dateFormatPattern)Converts a String to a Date, using the specified pattern.
(see java.text.SimpleDateFormat for pattern description)
Date date = null;
if (dateFormatPattern == null) {
dateFormatPattern = "yyyy-MM-dd";
}
synchronized (dateFormat) {
dateFormat.applyPattern(dateFormatPattern);
dateFormat.setLenient(false);
date = dateFormat.parse(dateString);
}
return date;
|
public static java.lang.String | toHTMLString(java.lang.String in)Returns the specified string converted to a format suitable for
HTML. All signle-quote, double-quote, greater-than, less-than and
ampersand characters are replaces with their corresponding HTML
Character Entity code.
StringBuffer out = new StringBuffer();
for (int i = 0; in != null && i < in.length(); i++) {
char c = in.charAt(i);
if (c == '\'") {
out.append("'");
}
else if (c == '\"") {
out.append(""");
}
else if (c == '<") {
out.append("<");
}
else if (c == '>") {
out.append(">");
}
else if (c == '&") {
out.append("&");
}
else {
out.append(c);
}
}
return out.toString();
|
public static java.lang.Number | toNumber(java.lang.String numString, java.lang.String numFormatPattern)Converts a String to a Number, using the specified pattern.
(see java.text.NumberFormat for pattern description)
Number number = null;
if (numFormatPattern == null) {
numFormatPattern = "######.##";
}
synchronized (numberFormat) {
numberFormat.applyPattern(numFormatPattern);
number = numberFormat.parse(numString);
}
return number;
|