1.0.9 • Published 6 months ago

domain-validation-email-publlic v1.0.9

Weekly downloads
-
License
ISC
Repository
github
Last release
6 months ago

domain-validation-email-publlic

A lightweight and easy-to-use React npm package for validating email addresses and checking if they belong to public domains. This package is designed to be used in React applications to enhance the validation of email inputs in forms.

Installation

npm i domain-validation-email-publlic

Usage

import React, { useState } from 'react';
import emailValidate from 'domain-validation-email-publlic';

function MyForm() {

const [error, setError] = useState(undefined); 
const [email, setEmail] = useState(null) 

const handleChangeEmail = (e) => { 
const inputValue = e.target.value;
if (!emailValidate(inputValue)) {
  setError({
    ...error,
    email:
      inputValue !== ""
        ? "Please enter a valid business email"
        : inputValue === ""
          ? "Email is required"
          : "",
  });
} else {
  setError({
    ...error,
    email: "",
  });
}
setEmail(inputValue)
};

const handleSubmit = (e) => { e.preventDefault();
console.log('Form submitted with data:', email);
};

 return ( 
  
  <div className="email-form"> 
   <h2>Sample React Form</h2>
    <form onSubmit={handleSubmit}>
        <label htmlFor="email">Email:</label>
        <input
          type="email"
          id="email"
          name="email"
          value={email}
          onChange={handleChangeEmail}
          required
        />
        <span style={{ color: 'red' }}>{error?.email}</span>
      <div>
        <button type="submit">Submit</button>
      </div>
    </form>
  </div>
);
}

export default MyForm;

Features

  • Email format validation using a regular expression.
  • Check if the email domain belongs to a predefined list of public domains.
  • Easily integrate with React forms for enhanced email validation.

License

ISC License

1.0.9

6 months ago

1.0.8

6 months ago

1.0.7

6 months ago

1.0.6

6 months ago

1.0.5

6 months ago

1.0.4

6 months ago

1.0.3

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago