The isCEP
function checks if the input string is a valid Brazilian ZIP Code (CEP). It returns true
if the CEP is valid, and false
otherwise.
The function can be imported using ES6 syntax from the "multiform-validator" package:
import { isCEP } from 'multiform-validator';
Alternatively, you can import the function using CommonJS syntax with require
(Node.js):
const { isCEP } = require('multiform-validator');
The function takes one parameter:
cep
(string) - The input string to check if it is a valid Brazilian ZIP Code (CEP).// Example 1 - Checking if the CEP is valid with dashes
const result1 = isCEP('12345-678');
console.log(result1); // true
// Example 2 - Checking if the CEP is valid without dashes
const result2 = isCEP('12345678');
console.log(result2); // true
// Example 3 - Checking an invalid CEP with an incorrect format
const result3 = isCEP('12.345-678');
console.log(result3); // false
The function expects the input to be passed as a string.