Validating CPF, CNPJ, Email, Phone, and Zip Code in SQL Server

Views: 12.080
Reading Time: 2 minutes

Hello people,
Alright?

Today I will be introducing some functions that will help them improve validations in their routines, such as validating a CPF from your base is valid or not.

Zip Validation
This is a simple validation, which only verifies that the number of characters is correct and that all of the entered string has 8 numeric characters. For stronger validation, I suggest that a database be purchased from the Post Office and the validation function should consult with that database to confirm CEP data and veracity.

Email Validation
This function does an address validation using an email validation mask. Strings like “[Email protected]”Or“ test ”will not be validated.

CPF Validation
This function will validate the number of CPF digits (must have 11), validate if the reported CPF is not in the list of repeated CPF's, but “pass” the standard validations, and calculates and validates the reported CPF to identify if it is. valid or not.

Validation of CNPJ
This function will validate the number of CNPJ digits (must have 14) and perform the calculation and validation of the entered CNPJ to identify whether or not it is valid.

CPF and CNPJ Validation
This function aims to perform the CPF and CNPJ validation, using the above functions depending on the number of characters of the entered Document No.

Phone Validation
This function will check the number of digits in the phone and if the number entered is not just repeated numbers.

Extra function
You may have noticed that the function to validate phone has a dependency, which is fncRecover_Number. This function is intended to return only numeric characters (0 to 9) and a string, removing strings, accents, special characters, etc.

If you want to download the file with all the scripts presented directly, click on the link
SQL Server - Validation Functions

That's it.
To the next.