Note that there are some explanatory texts on larger screens.

plurals
  1. POBest Refactor to Handle Multiple jQuery Email Field Form Validation
    primarykey
    data
    text
    <p>What is the best way to refactor the attached code to accommodate multiple email addresses?</p> <p>The attached HTML/jQuery is complete and works for the first email address. I can setup the other two by copy/pasting and changing the code. But I would like to just refactor the existing code to handle multiple email address fields.</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script src="includes/jquery/jquery-1.2.6.min.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script language="javascript"&gt; $(document).ready(function() { var validateUsername = $('#Email_Address_Status_Icon_1'); $('#Email_Address_1').keyup(function() { var t = this; if (this.value != this.lastValue) { if (this.timer) clearTimeout(this.timer); validateUsername.removeClass('error').html('Validating Email'); this.timer = setTimeout(function() { if (IsEmail(t.value)) { validateUsername.html('Valid Email'); } else { validateUsername.html('Not a valid Email'); }; }, 200); this.lastValue = this.value; } }); }); function IsEmail(email) { var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; if (regex.test(email)) return true; else return false; } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div&gt; &lt;label for="Email_Address_1"&gt;Friend #1&lt;/label&gt;&lt;/div&gt; &lt;input type="text" ID="Email_Address_1"&gt; &lt;span id="Email_Address_Status_Icon_1"&gt;&lt;/span&gt; &lt;/div&gt; &lt;div&gt; &lt;label for="Email_Address_2"&gt;Friend #2&lt;/label&gt;&lt;/div&gt; &lt;input type="text" id="Email_Address_2"&gt; &lt;span id="Email_Address_Status_Icon_2"&gt;&lt;/span&gt; &lt;/div&gt; &lt;div&gt; &lt;label for="Email_Address_3"&gt;Friend #3&lt;/label&gt;&lt;/div&gt; &lt;input type="text" id="Email_Address_3"&gt; &lt;span id="Email_Address_Status_Icon_3"&gt;&lt;/span&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload