You can call functions using CriteriaBuilder.function(name, ret_type, args)
.
You haven't said what DBMS your are using, so I'm assuming you have some function available that you could call in SQL like this:
SELECT * FROM user_account WHERE is_numeric(userCode);
You could represent that in Criteria API as follows:
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<User> query = builder.createQuery(User.class);
Root<User> root = query.from(User.class);
Path<String> userCode = root.get(User_.userCode);
Expression<Boolean> numeric = builder.function("is_numeric", Boolean.class, userCode);
query.select(root).where(numeric);
See API Doc for function(...)
.
EDIT possible function in MySQL (untested)
CREATE FUNCTION is_numeric(val VARCHAR(1024))
RETURNS TINYINT(1) DETERMINISTIC
RETURN val REGEXP '^(-|\\+)?([0-9]+\\.[0-9]*|[0-9]*\\.[0-9]+|[0-9]+)$';
(source)