domain-validation-email-publlic
v1.0.9
Published
Validates public domains
Downloads
4
Maintainers
Readme
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