Email Validation script Required

venkateshdhanap
Tera Contributor

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

6 REPLIES 6

Thanks


pawan k singh
Tera Guru

Try below background script and modify it.

// Get email address from field
var emailAddress= "123gmail.com";

//If Email address is valid, take some aciton.For example printing success message below
if (/^(([^<>()[\]\\.,;:\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,}))+$/.test(emailAddress)){
gs.info("Valid Email Address");
}

//If Email address is not valid, stop form submission or take some action
else{
gs.info("The email address format is invalid");
}

Regards

Pawan K Singh