In my db I store telephone numbers of things as input by the user (I want to let user decide how he format their phone number)
when users search for a phone number they most likely wont format the number in a way that I can just compare the two strings. Even 'like' wont do the trick since maybe the number has parenthesis or some other usual phone separator in the middle.
I want to be able to compare each telephone on the DB with with my search criteria after applying a filter and comparing the results. So far the filter I want to apply is this one:
private String numberFilter(String num){
num = num.replace("+", "00");
num = num.replace("(", "");
num = num.replace("(", "");
num = num.replace("-", "");
num = num.replace(" ", "");
if (num.contains("ext"))
num = num.substring(0, num.indexOf("ext"));
return num;
}
And what I'm doing to compare the telephones (still missing the filter)
public List<Entity> getEntityByTelephone(String telephone) {
DetachedCriteria criteria = DetachedCriteria.forClass(Entity.class);
criteria.createAlias("telephones", "tl", CriteriaSpecification.INNER_JOIN);
criteria.add(Restrictions.like("tl.number", telephone));
return (List<Entity>) getHibernateTemplate().findByCriteria(criteria);
}
So help on a way to use the filter above as a comparator in hibernate would be appreciated