2025-11-10 12:27:02 +07:00

20 lines
497 B
Go

package validasi
import "fmt"
// IsUsiaProduktif returns true if age is between 18 and 60 inclusive.
func IsUsiaProduktif(age int) bool {
return age >= 18 && age <= 60
}
// ValidateUsia returns nil when usia produktif, otherwise an error explaining why.
func ValidateUsia(age int) error {
if age < 0 {
return fmt.Errorf("umur tidak boleh negatif")
}
if IsUsiaProduktif(age) {
return nil
}
return fmt.Errorf("umur %d bukan usia produktif (18-60)", age)
}