π IP Validation in Zod
Easily validate IPs in your project with Dymo API integrated with Zod.
A better, simpler way to validate IPs with Dymo API + Zod in a single line of code!
About IP Validation
What is IP Validation?
IP validation uses Dymo API to check for fraud, invalid addresses, and more. All async validations require
parseAsync().Usage
To start validating emails in your project with Zod, create a schema using dymoClient.ipSchema():
import { z } from "zod";
import DymoAPIZod from "@dymo-api/zod";
const dymoClient = new DymoAPIZod({ apiKey: "PRIVATE_TOKEN_HERE" });
const userSchema = z.object({
ip: dymoClient.ipSchema(),
email: dymoClient.emailSchema(),
username: z.string().min(3),
age: z.number().int().min(0)
});
Validating Data
(async () => {
const validatedUser = await userSchema.parseAsync({
ip: "52.94.236.248",
email: "[email protected]",
username: "build",
age: 10
});
console.log(validatedUser);
/*
{
ip: "52.94.236.248",
email: "[email protected]", // normalized by Dymo API
username: "build",
age: 10
}
*/
})();
Handling Invalid Emails
The schema will automatically throw an error if the email is fraudulent or invalid:
try {
await userSchema.parseAsync({
ip: "228.49.142.11",
email: "[email protected]",
username: "build",
age: 10
});
} catch (err) {
console.error("Validation failed:", err.errors);
/*
[
{ path: ["ip"], message: "Invalid IP" }
]
*/
}
Optional Flags (for direct plugin-style usage)
You can pass options when creating the DymoAPIZod instance to customize behavior:
const dymoClient = new DymoAPIZod({
apiKey: "PRIVATE_TOKEN_HERE",
rules: {
ip: {
deny: ["FRAUD", "INVALID", "TOR_NETWORK"]
}
}
});
rules: Customize which IP rules to apply.parseAsync()must be used because the validator queries the Dymo API.
Examples with Other Validators
You can also create schemas for IPs, phones, and passwords:
const userSchema = z.object({
email: dymoClient.emailSchema(),
ip: dymoClient.ipSchema(),
phone: dymoClient.phoneSchema(),
// Coming Soon.
password: dymoClient.passwordSchema()
});
Important: All async validators require
parseAsync()because they make API requests.
IP Rules
| Rule | Default | Premium | Description |
|---|---|---|---|
FRAUD | β | β | Fraud detection |
INVALID | β | β | Invalid IP format |
TOR_NETWORK | β | β | Tor network detection |
COUNTRY:<COUNTRY_CODE> | β | β | Block an IP based on its country; you must use ISO 3166-1 alpha-2. |
HIGH_RISK_SCORE | β | β | High risk score detection |
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
apiKey | String | β | Your Dymo API key |
rules | Rules | β | Customize which rules to apply |
parseAsync() | Function | β | Must be called to validate async email rules |
π‘ Tip: Using DymoAPIZod with Zod lets you combine real-time fraud checks with normal Zod validations in a single schema for secure, consistent, and easy-to-maintain validation.