Get the App
SLTechnology News&Howtos  ›  Database  › 

Oracle determines whether the mobile phone number is legal.

Shulou Source: shulou.com Published: 2022-06-01 21:24:06 10月03日 Update

Legal mobile phone numbers: all 11 digits and start with 13, 15, 18.

create or replace function isLegal

(phoneNumber in varchar2) return number

--Returns 0 for legal, returns 1 for illegal

as

begin

if length(phoneNumber) != 11 then return 1;

elsif replace(translate(phoneNumber, '0123456789', '0'), '0', '') IS not NULL THEN

--dbms_output.put_line(phoneNumber ||'is not a numeric sequence of [0-9]');

return 1;

elsif substr(phoneNumber,1,2) not in ('13','15','18') then

--dbms_output.put_line ('First two digits are illegal: '||substr(phoneNumber,1,2));

return 1;

else

--dbms_output.put_line ('legal number');

return 0;

end if;

exception when others then

--dbms_output.put_line ('Exception:');

return 1;

end isLegal;

Tags: Legal number number mobile number digit sequence beginning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Shulou Technology macOS Microsoft vpn