Click on the banner to learn about and purchase my database training on Azure

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

Views: 22.873 views
Reading Time: 2 minutes

Hello people,

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 performs 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 digits of the CPF (must have 11), validate that the informed CPF is not in the list of repeated CPF's, but that “pass” through the standard validations and does the calculation and validation of the informed 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.