New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

email-password-validator

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

email-password-validator

A simple npm package for validating email, password, names, and custom fields.

latest
npmnpm
Version
1.0.1
Version published
Weekly downloads
3
200%
Maintainers
1
Weekly downloads
 
Created
Source

README.md

#  email-password-validator

A lightweight TypeScript-based package for validating **emails, passwords, names, and custom fields** in real-time.  
Designed for use in **Node.js** and **frontend frameworks** like React, Vue, or Angular.

---

##  Installation

```bash
npm install email-password-validator

🔧 Usage

Email Validation

import { validateEmail } from "email-password-validator";

console.log(validateEmail("test@example.com"));
// { valid: true }

console.log(validateEmail("wrong-email"));
// { valid: false, error: "The provided email is an invalid email format" }

Password Validation

import { validatePassword } from "email-password-validator";

console.log(validatePassword("MyP@ssw0rd"));
// { valid: true, errors: [] }

console.log(validatePassword("weak"));
// { valid: false, errors: ["Password must be at least 8 characters", "At least one uppercase letter required", ...] }

Custom rules:

validatePassword("password123", { minLength: 6, requireSpecialChar: false });
// { valid: true, errors: [] }

Name Validation

import { validateName } from "email-password-validator";

console.log(validateName("John Doe"));
// { valid: true }

console.log(validateName("J1"));
// { valid: false, error: "Name can only contain letters and spaces" }

Custom Validation

import { validateCustom } from "email-password-validator";

// Username validator: letters, numbers, underscores, 3–15 chars
const usernameCheck = validateCustom(
  "user_123",
  (val) => /^[a-zA-Z0-9_]{3,15}$/.test(val),
  "Username must be 3-15 characters, letters/numbers/underscore only"
);

console.log(usernameCheck);
// { valid: true }

Testing

This package comes with Jest tests. Run:

npm test

Features

    • Email validation (basic RFC-compliant format)
    • Password validation (configurable rules: length, numbers, uppercase, special chars)
    • Name validation (letters + spaces, min/max length)
    • Custom validation (use your own regex or function)
    • TypeScript support (auto-complete & type safety)

Example (React Form)

import React, { useState } from "react";
import { validateEmail, validatePassword, validateName } from "email-password-validator";

export default function ExampleForm() {
  const [email, setEmail] = useState("");
  const [password, setPassword] = useState("");

  const emailResult = validateEmail(email);
  const passwordResult = validatePassword(password);

  return (
    <div>
      <input value={email} onChange={(e) => setEmail(e.target.value)} placeholder="Email" />
      {!emailResult.valid && <p style={{ color: "red" }}>{emailResult.error}</p>}

      <input type="password" value={password} onChange={(e) => setPassword(e.target.value)} placeholder="Password" />
      {!passwordResult.valid && (
        <ul style={{ color: "red" }}>
          {passwordResult.errors.map((err, i) => <li key={i}>{err}</li>)}
        </ul>
      )}
    </div>
  );
}

License

MIT © 2025 [ENIGMA]

Keywords

validator

FAQs

Package last updated on 16 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts