Create validation utility functions
✓Works with OpenClaudeYou are a utility developer creating reusable validation functions. The user wants to build a set of validation utilities that can be used across projects for common data validation scenarios.
What to check first
- Determine target language/framework (JavaScript/TypeScript, Python, etc.)
- Review existing validation libraries (Zod, Yup, Pydantic) to avoid reinventing
- Identify which validation patterns are most frequently needed in your codebase
Steps
- Create a new
validation.jsorvalidation.tsfile in your utils directory - Define validators for primitive types:
isString(),isNumber(),isBoolean(),isArray() - Build composite validators:
isEmail(),isUrl(),isPhoneNumber()using regex patterns - Implement conditional validators:
isRequired(),hasMinLength(),hasMaxLength() - Add object/schema validators:
validateObject()that checks multiple fields against rules - Create error collection: return structured validation errors with field names and messages
- Export all validators as named exports for flexible imports
- Add type definitions if using TypeScript with clear return types (
booleanorValidationError[])
Code
export interface ValidationError {
field: string;
message: string;
}
export interface ValidationRule {
[key: string]: Array<(value: any) => boolean | string>;
}
// Primitive validators
export const isString = (value: any): boolean => typeof value === 'string';
export const isNumber = (value: any): boolean => typeof value === 'number' && !isNaN(value);
export const isBoolean = (value: any): boolean => typeof value === 'boolean';
export const isArray = (value: any): boolean => Array.isArray(value);
// String format validators
export const isEmail = (value: string): boolean => {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(value);
};
export const isUrl = (value: string): boolean => {
try {
new URL(value);
return true;
} catch {
return false;
}
};
export const isPhoneNumber = (value: string): boolean => {
const phoneRegex = /^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/;
return phoneRegex.test(value);
};
// Constraint validators
export const isRequired = (value: any): boolean => {
if (typeof value === 'string') return value.trim().length > 0;
return value !== null && value !== undefined;
};
export const hasMinLength = (min: number) => (value: string): boolean => {
return isString(value) && value.length
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related General / Utility Skills
Other Claude Code skills in the same category — free to download.
Env Setup
Set up development environment from scratch
Gitignore Generator
Generate .gitignore for any project type
NPM Publish
Prepare and publish npm package
Error Boundary
Create error boundary components
Feature Flag
Implement feature flag system
Config Manager
Create application configuration manager
Date Time Helper
Create date/time utility functions
String Utils
Create string manipulation utilities
Want a General / Utility skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.