Repository: logaretm/vee-validate (ts)

Issue:
email validation rule regex is not correct
### What happened?

Regex used in email validation accepts invalid characters like # and $ and %

### Reproduction steps

1. Open sandbox
2. Type "email#%@test.com" (which obviously is a wrong email address) in input
3. No error will show

### Version

Vue.js 3.x and vee-validate 4.x

### What browsers are you seeing the problem on?

- [ ] Firefox
- [X] Chrome
- [ ] Safari
- [ ] Microsoft Edge

### Relevant log output

_No response_

### Demo link

https://codesandbox.io/s/vee-validate-4-9-0-radio-group-forked-d6wgv8

### Code of Conduct

- [x] I agree to follow this project's [Code of Conduct](CONDUCT.md)

Pull request description:
fix: use a better email re pulled from zod closes #4585
closes #4585 

Patch:
diff --git a/.changeset/violet-apes-tan.md b/.changeset/violet-apes-tan.md
new file mode 100644
index 00000000..cd12d4a3
--- /dev/null
+++ b/.changeset/violet-apes-tan.md
@@ -0,0 +1,5 @@
+---
+"@vee-validate/rules": patch
+---
+
+fix: use a better email re pulled from zod closes #4585
diff --git a/packages/rules/src/email.ts b/packages/rules/src/email.ts
index f3aecf85..9e29478e 100644
--- a/packages/rules/src/email.ts
+++ b/packages/rules/src/email.ts
@@ -1,18 +1,19 @@
 /* eslint-disable no-useless-escape */
 import { isEmpty } from './utils';
 
+// https://github.com/colinhacks/zod/blob/master/src/types.ts#L567
+const emailRE = /^(?!\.)(?!.*\.\.)([A-Z0-9_+-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
+
 const emailValidator = (value: unknown) => {
   if (isEmpty(value)) {
     return true;
   }
-  const re =
-    /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
 
   if (Array.isArray(value)) {
-    return value.every(val => re.test(String(val)));
+    return value.every(val => emailRE.test(String(val)));
   }
 
-  return re.test(String(value));
+  return emailRE.test(String(value));
 };
 
 export default emailValidator;


Test patch:
diff --git a/packages/rules/tests/email.spec.ts b/packages/rules/tests/email.spec.ts
index 5b5a2d6d..1f3d733d 100644
--- a/packages/rules/tests/email.spec.ts
+++ b/packages/rules/tests/email.spec.ts
@@ -4,7 +4,6 @@ test('validates that the string is a valid email address', () => {
   expect(validate('someone@example.com')).toBe(true);
   expect(validate('someone@example.co')).toBe(true);
   expect(validate('someone123@example.co.uk')).toBe(true);
-  expect(validate('Pelé@example.com')).toBe(true);
   expect(validate('very.common@example.com')).toBe(true);
   expect(validate('other.email-with-dash@example.com')).toBe(true);
   expect(validate('disposable.style.email.with+symbol@example.com')).toBe(true);
@@ -15,6 +14,7 @@ test('validates that the string is a valid email address', () => {
   expect(validate([])).toBe(true);
 
   // invalid
+  expect(validate('Pelé@example.com')).toBe(false);
   expect(validate('@example.com')).toBe(false);
   expect(validate('@example')).toBe(false);
   expect(validate('undefined')).toBe(false);