Skip to content

Commit a074bed

Browse files
authored
added comprehensive email regex pattern (#2052)
1 parent e1e98f0 commit a074bed

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
onSubmit Function: This client script validates the email format when the form is submitted.
2-
Regular Expression: It uses a regex pattern to check if the entered email matches a standard email format.
2+
Regular Expression: It uses a comprehensive email regex pattern to check if the entered email matches a standard email format.
3+
4+
This pattern can handles:
5+
- Quoted local parts (`"john doe"@example.com`)
6+
- Dots within the local segment (`first.m.last@subdomain.org`)
7+
- IP-based domains (`user@[192.168.1.1]`)
8+
39
Error Message: If the email is invalid, an error message is displayed, and form submission is prevented.

Client-Side Components/Client Scripts/Validate Email Format/ValidateEmailFormat.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
function onSubmit() {
44
var emailField = g_form.getValue('email');
5-
var emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
5+
//Comprehensive email regex pattern
6+
var emailPattern = /^(([^<>()\[\]\\.,;:\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,}))$/;
67

78
if (!emailPattern.test(emailField)) {
89
g_form.addErrorMessage('Please enter a valid email address.');

0 commit comments

Comments
 (0)