toLowerCase Problems

toLowerCase Problems

My application includes several forms which each ask for the users name and email address. The email address is used as the identifier to cross reference records on all forms for fetching data and lookup fields.

Everything was working fine until I realized that is a user inputted their email address with different capitalization, the scripts would not be able to match up their records because strings are case sensitive.

I looked at these hep articles  <string>.toLowerCase()  and  Built-in-functions - String  and began to add 

input.Email = input.Email.toLowerCase();

to every script relating to email fields. To my horror, when I accessed my application some forms would not open, some fields would get stuck.

I found this support article  Enforce Lowercase which confirmed my suspicions that my forms and fields were hung in endless loops. So I tried the first suggestion and I made a separate field email_look_up which would store the email address all in lower case.

My scripts now had lots of

input.email_look_up = input.Email.toLowerCase();

I was still having looping issues. 

So I tried employing the second suggestion

if (input.Email  !=  input.Email.toLowerCase())
{
    input.email_look_up = input.Email.toLowerCase();
}

This cleared up many of form loading issues, but individual fields that depended on fetch and lookup are still hanging.

This field is supposed to collect a users email address and then auto populate the First and Last name fields based on their record fetched from the New_Application form. But it loops hopelessly.

if (input.Email  !=  input.Email.toLowerCase())
{
    input.email_look_up = input.Email.toLowerCase();
}
myapplication  =  New_Application  [email_look_up == input.email_look_up];
input.First_Name = myapplication.First_Name;
input.Last_Name = myapplication.Last_Name;

Then I wondered if it were looping because the if block could pass false if the Email was in fact lower case and then the script would not execute correctly. So I tried

input.email_look_up = input.Email;
if (input.Email  !=  input.Email.toLowerCase())
{
    input.email_look_up = input.Email.toLowerCase();
}
myapplication  =  New_Application  [email_look_up == input.email_look_up];
input.First_Name = myapplication.First_Name;
input.Last_Name = myapplication.Last_Name;

But that didn't fix it. I need help.