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

PrashantLearnIT
Tera Sage

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)

lSurya 24
Giga Guru

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/


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



Hello Venkatesh,



As I said you have to modify the regex as per your requirement. And you can test that in https://regex101.com/