'posix regulation does not work with postgreSQL in trigger function

I am working on a trigger function, and I only want to insert the data when it satisfies specific format. So I tried to use posix regulation expressions. But none of it seems working.

            if(new.tin ~ '\d{10}') then
                if not exists(
                    select *
                    from taxcodes
                    where code = substr(new.tin, 1, 4)
                ) then return null;
                end if;
            end if;


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source