Skip to content

Commit e781dd0

Browse files
Add onChange email validation script for real-time feedback
1 parent 990e2e5 commit e781dd0

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function onChange(control, oldValue, newValue, isLoading) {
2+
if (isLoading || newValue === '') {
3+
return;
4+
}
5+
6+
// Regular expression for email validation
7+
var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
8+
9+
// Test the email against the pattern
10+
if (!emailPattern.test(newValue)) {
11+
g_form.showFieldMsg('email_field_name', 'Invalid email format. Example: user@example.com', 'error');
12+
g_form.hideFieldMsg('email_field_name', true); // Clear info messages
13+
} else {
14+
g_form.hideFieldMsg('email_field_name'); // Clear error message
15+
g_form.showFieldMsg('email_field_name', 'Valid email address', 'info');
16+
}
17+
}

0 commit comments

Comments
 (0)