Reputation: 11
I want to validate a string. The conditions are :
I want to verify this using REGEXP_LIKE()
. Please suggest.
Upvotes: 1
Views: 7456
Reputation: 1599
You should be able to use the following REGEXP_LIKE to validate your inputs:
REGEXP_LIKE(td.text_value, '^[A-Z][0-9]{8}$')
Explaining the regular expression:
^
- Beginning of String[A-Z]
- A Capital Letter[0-9]{8}
- Exactly 8 digit characters$
- End of StringHere is a query validating certain use cases:
WITH test_data (text_value) AS
(
SELECT 'A12345678' FROM DUAL UNION ALL
SELECT 'a12345678' FROM DUAL UNION ALL
SELECT 'A1234567' FROM DUAL UNION ALL
SELECT 'A123456789' FROM DUAL UNION ALL
SELECT '$12345678' FROM DUAL
)
SELECT td.text_value,
CASE WHEN REGEXP_LIKE(td.text_value, '^[A-Z][0-9]{8}$') THEN 'Y' ELSE 'N' END AS VALID
FROM test_data td
Here is the link to Oracle's Regular Expression documentation (Link)
Additionally, here is a DBFiddle running the above query (Link)
Upvotes: 3