i have a web application. In the customer form i make a empty validation, but now i have to test if the value has a special characters to, like a: ÁÄÉëÍÏ......
this is the .java empty validation:
private void testFields(String name) {
if (applicationField == null) {
LOG.error("The request is invalid");
}
try {
Field f = applicationField.class.getDeclaredField(name);
f.setAccessible(true);
Object value = f.get(applicationField);
boolean emp = false;
if (value instanceof String) {
String strVal = (String) value;
if (StringUtils.isEmpty(strVal)) {
emp = true;
}
} else if (value == null) {
emp = true;
}
if (emp) {
addMissingField(name);
}
} catch (Exception e) {
LOG.error("Failed to validate the field: " + name, e);
}
}
private void addMissingField(String name){
if (StringUtils.isEmpty(missingFields)) {
missingFields = name;
} else {
missingFields += " " + name;
}
}
In the .jsp i make this in the submit button:
$("#submit")
.button()
.click(function(event) {
event.preventDefault();
var submitButton = $(this);
submitButton.button("disable");
$("input:text").each(function(idx,elem){
$(elem).val($(elem).val().toUpperCase());
});
var form = $("#customerForm");
var action = form.attr('action');
var queryString = form.serialize();
console.log(notifier);
var taskId = notifier.start("Processing Request");
$.ajax({
method: "post",
url: action,
data: queryString,
statusCode: {
201: function() {
window.location.replace(".........");
}
}
}).always(function(data){
notifier.done(taskId);
submitButton.button("enable");
}).done(function(data){
if(data.missingFields){
messageDialog("Sorry, Missing required fields to register the application", true);
markMissingFields(data.missingFields);
console.log("This is the missing Fields: " + data.missingFields);
}
}).fail(function(data){
messageDialog("There was an error processing the request", true);
});
});
So, the empty validation works perfectly. But sometime the users insert data like a: MÖDRIC, JHÖN or CÁRLOS creating problems in the difference procedure of the database.
I wanna know how can i do to include a special characters validation testing if the values are empty or has a special characters at the same time.
So i need a good way to make this in the .java or .jsp.