Help with creating T-SQL function syntax

Hello again, im sorry english is not my first language. so ill try to describe here what im trying to do

The input parameter into the function is a social number in one of these formats:
• YYMMDDXXXX
• YYMMDD-XXXX
The control numer is the last X which is the number you get after all calculations which verifies your birthdate.

The function should return 1 if the check digit is correct, 0 if the check digit is incorrect or if there is another error.

Using this method:
Multiply the numbers by year of birth, month, day and number alternately by 2 and 1.
Add the numbers in the products. In numbers exceeding 9, the numbers are added, e.g. 12 is calculated as 1 + 2.
So e.g if i put 19900210- 2450 it counts it times 1 and 2 alternately.
Subtract the singular digit from the number from the number 10.
The residual digit becomes the control digit.
If the remainder is 10, the check digit becomes 0.