Validate SSN
select case when regexp_like('987-65-4321' ,'^[0-9]{3}-[0-9]{2}-[0-9]{4}$') then
'Match Found' else 'No Match Found' end as output from dual;
Output: Match Found
Input: 987-654-3210
Output: No match found
^ start of the string
[0-9]{3} three occurrences of digits from 0-9
- followed by hyphen
[0-9]{2} two occurrences of digits from 0-9
- followed by hyphen
[0-9]{4} four occurrences of digits from 0-9
$ end of the string
The above pattern can also be used to validate phone numbers with little
customization.