I’m using PostgreSQL for storing the data. It is linked with Spring boot as application server. I’m using JPA
to access the data.
Now, I have a entity named custom_user
with string property mobile_number
. The format of mobile_number
is +{{country_code}}.{{actual_number}}
(ex. +91.123, +92.456). Now, I want to filter this records using search queries such as “+91”, “123”, “+91123”, “+924”.
I tried following query but it is not working
SELECT ma.*
FROM custom_user cu
AND (
cu.mobile_number LIKE CONCAT(:mobileNumber, '.%')
OR (
cu.mobile_number REGEXP CONCAT('^\+', '[0-9]*\.?', '[0-9]*')
AND (
cu.mobile_number LIKE CONCAT(:mobileNumber, '.%')
OR REPLACE(cu.mobile_number, '.', '') LIKE CONCAT(REPLACE(:mobileNumber, '+', ''), '.%')
)
)
)