regex is correct but some issue in the script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2024 11:25 AM
Hi,
I wrote the regex for validating the email ID, but the problem is coming with respect to the code. Kindly help.
function onSubmit() {
var email_ID = g_form.getValue("email");
var testEmail = /^([a-z0-9A-Z\_\.]*)@([a-z\.]*)$/;
if (!testEmail.test(email_ID)) {
g_form.addErrorMessage("invalid email");
return false;
}
return true;
Regards
Suman P.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2024 12:53 PM
Ah, so you need domain part of the email always lower case. What is the email address you are testing which is not working?
Your regex (below) works in background script and it passes for
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2024 10:38 PM
@Community Alums
Try with below code once:
function onSubmit() {
var email_ID = g_form.getValue("email");
var testEmail = /^[a-zA-Z0-9._]+@[a-z]+\.[a-z]+$/;
if (!testEmail.test(email_ID)) {
g_form.addErrorMessage("Invalid email");
return false;
}
return true;
}
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2024 11:49 AM
For me, this regex worked:
Regards,
Sharad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2024 10:30 PM - edited 04-09-2024 10:35 PM
Hi @Community Alums
I have updated the code , u can try this logic ,
function onSubmit() {
var email_ID = g_form.getValue("email");
var testEmail = /^(?![\.])[a-zA-Z0-9!#$%*\/?|^{}`~&'\\+\-=_.]+(?<![.]+)@(?![\.-])[a-zA-Z0-9-_\.]+(\.[a-zA-Z0-9_]+)$/;
if (!testEmail.test(email_ID)) {
g_form.addErrorMessage("Invalid email");
return false;
}
return true;
}
You can find many regular expressions for email validation. However, you can try using an out-of-the-box (OOTB) regular expression.
SS - 1
SS - 2 : In the marked field, you can use your regex for email validation.
If this solution resolves your query, kindly mark it as the accepted solution and give it a thumbs up.
Thanks,
Subhashis Ratna
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2024 10:45 PM
Hi @Community Alums
Please have a loot at this-
function onSubmit() {
var email_ID = g_form.getValue("email");
var testEmail = /^[a-zA-Z0-9._]+@[a-z]+\.[a-z]+$/;
if (!testEmail.test(email_ID)) {
g_form.addErrorMessage("Invalid email format");
return false;
}
return true;
}
Regards,
Amit