Jump to content
  • 0

Check Field For Email Domain


Carlson
 Share

Question

2 answers to this question

Recommended Posts

  • 0

Hello Carl,

 

If I understand you correctly, you can add a Header&Footer element, select the Footer element, click the Source button and enter the following code:

<SCRIPT LANGUAGE="JavaScript">

function check_Domain()
{
  var correct_domain = "com";
  var field_name = "text255";
  field_name = "InsertRecord" + field_name;
  var text_email = document.getElementById(field_name).value;
  if (text_email.length>0)
  {
    var last_point = text_email.lastIndexOf(".");
    if (last_point > 3)
    {
      var text_domain = text_email.slice(last_point+1);
      if (text_domain.toLowerCase()!=correct_domain.toLowerCase())
       {
        alert("incorrect domain!");
        return false;
       }
     }
    else 
    {
      alert("Email address is incorrect!");
      return false;
     }
  }
}

document.getElementById("caspioform").onsubmit=check_Domain;
</SCRIPT>
Please enter your values in lines
 
var correct_domain = "com";
var field_name = "text255";
 
I hope, it helps.
Link to comment
Share on other sites

  • 0
Jan,

 

I was able to modify the script to check full email domain not just the ending (.com, .net, etc). In this instance I want to make sure users only type an internal company email address and not external (yahoo, hotmail, etc).  I have checked and this script is working correctly. Thanks for your help!

 

 

<SCRIPT LANGUAGE="JavaScript">

 

function check_Domain()

{

  var correct_domain = "companyname.com";

  var field_name = "UserEmailAddress";

  field_name = "InsertRecord" + field_name;

  var text_email = document.getElementById(field_name).value;

  if (text_email.length>0)

  {

    var last_point = text_email.lastIndexOf("@");

    if (last_point > 3)

    {

      var text_domain = text_email.slice(last_point+1);

      if (text_domain.toLowerCase()!=correct_domain.toLowerCase())

       {

        alert("You must enter an email address ending with companyname.com.");

        return false;

       }

     }

    else 

    {

      alert("You must enter an email address ending with companyname.com.");

      return false;

     }

  }

}

 

document.getElementById("caspioform").onsubmit=check_Domain;

</SCRIPT>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...