Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.

fesa-academic-projects/cpf-rg-validator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

31 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“š CPF/RG Validator - Brazilian Document Validation

Tokyo Night Theme Preview
Tokyo Night Theme (Dark & Light Modes)

Spring Boot Version Java Version Tests Passed License

πŸ—‚οΈ Table of Contents


⭐ Features

Industrial-grade Brazilian document validation:

  • βœ… Dual Validation Modes
    • Single Mode: Real-time validation with instant feedback
    • Batch Mode: Process multiple documents (one per line)
  • πŸ” Two-Step Validation
    • Finite Automaton: Format verification via DFA (5 RG patterns β€’ 5 CPF patterns)
    • Check Digit: Mathematical validation using modulo 11
  • 🎨 Modern Interface
    • Responsive design with Tailwind CSS
    • Smooth dark/light mode transitions

πŸ”’ Accepted Formats

Valid RG Patterns
111111111 β€’ 11.111.111-1 β€’ 11111.111-1 β€’ 11.11111-1 β€’ 11111111-1

Valid CPF Patterns
11111111111 β€’ 111.111.111-11 β€’ 111111.111-11 β€’ 111.111111-11 β€’ 111111111-11


πŸ“Έ Screenshots

Automaton Diagram

Automaton Diagram
Finite State Machine with Transition Rules πŸ“₯ Download JFLAP Project File

πŸ“Š Complete Transition Table (Enum-based States)
State 0-9 x . -
β†’ Q0 Q1 ❌ ❌ ❌
Q1 Q2 ❌ ❌ ❌
Q2 Q3 ❌ Q12 ❌
Q3 Q4 ❌ Q22 ❌
Q4 Q5 ❌ ❌ ❌
Q5 Q6 ❌ Q20 ❌
Q6 Q7 ❌ Q29 ❌
Q7 Q8 ❌ ❌ ❌
Q8 Q9 Q19 ❌ Q21
Q9 * Q10 ❌ ❌ Q30
Q10 Q11 ❌ ❌ ❌
Q11 * ❌ ❌ ❌ ❌
Q12 Q13 ❌ ❌ ❌
Q13 Q14 ❌ ❌ ❌
Q14 Q15 ❌ ❌ ❌
Q15 Q16 ❌ Q20 ❌
Q16 Q17 ❌ ❌ ❌
Q17 Q18 ❌ ❌ ❌
Q18 Q19 Q19 ❌ Q21
Q19 * ❌ ❌ ❌ ❌
Q20 Q16 ❌ ❌ ❌
Q21 Q19 Q19 ❌ ❌
Q22 Q23 ❌ ❌ ❌
Q23 Q24 ❌ ❌ ❌
Q24 Q25 ❌ ❌ ❌
Q25 Q26 ❌ Q29 ❌
Q26 Q27 ❌ ❌ ❌
Q27 Q28 ❌ ❌ ❌
Q28 Q10 ❌ ❌ Q30
Q29 Q26 ❌ ❌ ❌
Q30 Q10 ❌ ❌ ❌

(Implemented using Java Enums and HashMaps)

Single Validation Mode

Single Validation
Single-document Text Input Validation

Batch Processing Mode

Batch Validation
Multi-document Text Input Validation


πŸ—οΈ Technical Implementation

Core Architecture

src/
β”œβ”€β”€ main
β”‚Β Β  β”œβ”€β”€ java/br/edu/fesa/validator
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ ValidatorApplication.java       # Main class
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ controller/DocumentController.java # REST endpoints
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ model/DocumentResultModel.java  # Validation result DTO
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ service/DocumentService.java    # Business logic
β”‚Β Β  β”‚Β Β  └── utils
β”‚Β Β  β”‚Β Β      β”œβ”€β”€ AFDValidator.java           # State machine implementation
β”‚Β Β  β”‚Β Β      └── CheckDigitValidator.java    # Digit calculation
β”‚Β Β  └── resources
β”‚Β Β      β”œβ”€β”€ templates/index.html            # Thymeleaf template
β”‚Β Β      └── static/css/styles.css           # Tailwind styles
└── test
    └── java/br/edu/fesa/validator
        β”œβ”€β”€ service/DocumentServiceTest.java    # 13 Tests
        └── utils
            β”œβ”€β”€ AFDValidatorTest.java          # 13 Tests
            └── CheckDigitValidatorTest.java   # 12 Tests

βš™οΈ Technologies

  • Backend: Spring Boot 3.4.2 + Java 17
  • Frontend: Thymeleaf + Tailwind CSS
  • State Machine: Enum-based DFA with HashMap transitions
  • Build: Maven 3.9+
  • Testing: JUnit 5 + Mockito (38 Total Tests)

πŸš€ Getting Started

Prerequisites

  • JDK 17
  • Maven 3.9+

Installation

git clone git@github.com:Rutpiv/cpf-rg-validator.git
cd cpf-rg-validator
mvn clean install

Running the Application

mvn spring-boot:run

Access: 🌐 http://localhost:8080


πŸ§ͺ Testing

Comprehensive validation coverage:

mvn test
  • βœ… 13 Service Tests (Business logic)
  • βœ… 13 Automaton Tests (State transitions)
  • βœ… 12 Check Digit Tests (Mathematical validation)

πŸ“œ License

Distributed under BSD 3-Clause License.
➑️ View Full License Text


πŸ‘₯ Authors

Students from Engenheiro Salvador Arena College:
➑️ Complete Contributors List


Built with β™₯ by Computer Engineering students
Compilers Course Project β€’ 2025 Semester