Email Validation script Required
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2017 10:31 PM
Hi All,
Need to validate on Email field with below condition (Wrote Onchange client script on Email part)
- uppercase and lowercase letters A to Z and a to z;
- digits 0 to 9 allowed at the end of local part
- Allows single quote( ' )
- Domain part must contains ( A-Z, 0-9, - )
- comments are allowed with parentheses at either end of the local-part; e.g. john.smith(comment)@example.com and (comment)john.smith@example.com are both equivalent to john.smith@example.com.
- special characters !#$%&'*+-/=?^_`{|}~;
- dot ., provided that it is not the first or last character unless quoted, and provided also that it does not appear consecutively unless quoted (e.g. John..Doe@example.com is not allowed but "John..Doe"@example.com is allowed);
- space and "(),:;<>@[\] characters are allowed with restrictions (they are only allowed inside a quoted string, as described in the paragraph below, and in addition, a backslash or double-quote must be preceded by a backslash);
Please provide the script for validate email with above conditions
Thanks in advance
Venkatesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2017 10:34 PM
Hi Venkatesh,
Use below script and try
- function ValidateEmail(mail)
- {
- if (/^\w+([\.-]?\ w+)*@\w+([\.-]?\ w+)*(\.\w{2,3})+$/.test(myForm.emailAddr.value))
- {
- return (true)
- }
- alert("You have entered an invalid email address!")
- return (false)
Please appreciate the efforts of community contributors by marking the appropriate response as the correct answer and helpful. This may help other community users to follow the correct solution in the future.
********************************************************************************************************
Cheers,
Prashant Kumar
ServiceNow Technical Architect
Community Profile LinkedIn YouTube Medium TopMate
********************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2017 10:40 PM
Hello Venkatesh,
Try below script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.hideErrorBox('u_contact_email');
var pattern =/^(([^<>()[\]\\.,;:\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,}))$/; // regex pattern
if(!pattern.test(newValue)){
g_form.showErrorBox('u_contact_email', getMessage('Invalid Email ID'));//show error messege
g_form.setValue(' u_contact_email', '');
}
}
And in your case, creatre and replace my regex patten if neccesaary and make changes in regex pattern in below link: https://regex101.com/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2017 02:55 AM
I have tried this code i can't able to give thse accetable email id's
john.smith(comment)@gmail.com
(comment)john.smith@example.com
Also i can't able to give special chars inside "" also
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2017 03:02 AM
Hello Venkatesh,
As I said you have to modify the regex as per your requirement. And you can test that in https://regex101.com/