Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Jquery No Email Verification

Avatar of spoggles
spoggles asked on
JavaScriptScripting LanguagesjQuery
12 Comments1 Solution376 ViewsLast Modified:
Hello experts!

Here is what I'm trying to accomplish. In the name field of my form, I do not want someone to be able to submit e-mails. I got something to work, but it doesn't work 100% of the time.

The way it is supposed to work is if someone puts an email address in the name field, a box below the name field will appear and say 'No Emails Allowed'. When you first come to the page, the no emails allowed shows up no matter what. When you refresh the page and something is already in the field, then it "works". Can you help me?

I have attached the relevant HTML code below and the Jquery code in the code field. Here is the link to the development form that I am working on: http://dev.mytucker.com/dev/devForm/decals.htm. This will allow you to see the full code.

<tr>
   <td><label for="Name_A">Agent Name: </label></td>
    <td><input id="Name_A" name="Name_A" type="text" /></td>                                
</tr>
//Start the No Email Address in the Name Fields    
    var hasError = false;
    var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

    var Name_A = $("#Name_A");
    var invalidName_A = $("#invalidName_A");
    var emailaddressVal_A = $("#Name_A").val();
   
    Name_A.blur(validateNoEmail);
   
    function validateNoEmail() {
                
        if (emailReg.test(emailaddressVal_A)) {
            invalidName_A.text("No Emails allowed");
            hasError = true;            
        }        
    }
ASKER CERTIFIED SOLUTION
Avatar of Greg Alexander
Greg AlexanderFlag of United States of America imageLead Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 12 Comments.
See Answers