}
public void writeJavaScriptValidation(
XFTextInputAttributes attribute,
StringBuffer sb) {
TextInputFormat format = getTextInputFormat2(attribute);
if (format != null) {
String pattern = format.getFormat();
pattern = extractPattern(pattern);
String caption = getPlainText(attribute.getCaption());
String errorMsg = getPlainText(attribute.getErrmsg());
if (errorMsg == null) {
// if no error message has been provided then we
// need to generate a sensible message
errorMsg = "Invalid input for " +
((caption != null) ? caption : " a form field");
}
// We generate the JavaScript to perform the validation
// If the attribute.emptryOK is true then we must test if
// the form field is not empty and if it fails the regex
// and only then generate the error message
sb.append("if(!(new RegEx(\"").append(pattern).append("\",")
.append("form.")
.append(attribute.getName()).append(".value).match())");
if (format.isEmptyOk()) {
sb.append(" && (form.").append(attribute.getName())
.append(".value!='')");
}
sb.append(") {\n errMsg += \"\\n").append(errorMsg).append("\";")
.append("}\n");