Click here to Skip to main content
15,906,106 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi every body

I use "test" function in java script to check the email address is entered by user ... my code doesn't work .

can any body help me??

thanks for your time
html code:
HTML
<form action="" method="POST" name="frm1">
 <table>
         <tr>
            <td>
                 Email :
            </td>
            <td>
                <input type="text" name="user_email" />
            </td>
        </tr>
        

        <tr>         
            <td>
                <input type="submit" value="submit" onclick="validateEmail(user_email)"  />
            </td>
        </tr>
    </table>
 </form>





JavaScript
<script language="JavaScript" type="text/javascript">

function validateEmail(email) { 
       //// email=document.forms["frm1"]["user_email"].value; // 

 var re = /^(([^<>()[\]\\.,;:\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,}))$/;
     
 return re.test(email);

</script>
Posted
Updated 26-Sep-13 6:47am
v2
Comments
Sergey Alexandrovich Kryukov 26-Sep-13 13:15pm    
sahrarainmelody 26-Sep-13 13:57pm    
yes exactly ... I think my wrong is in html code where I pass the email value to the function .I guess so

onclick="validateEmail(user_email)
sahrarainmelody 26-Sep-13 14:07pm    
onclick="validateEmail(document.getElementsById('user_email').value)
|
it doesn't work too |
I change name to Id

1 solution

Please see:
http://en.wikipedia.org/wiki/Regular_expression[^],
http://www.w3schools.com/jsref/jsref_obj_regexp.asp[^],
http://www.regular-expressions.info/tutorial.html[^],
http://www.regular-expressions.info/reference.html[^].

Please understand: Regular Exceptions are relatively easy to write but surprisingly hard to read and understand. That's why writing them from scratch is way easier then fixing one you got somewhere.

So, if the regular expression which you get somewhere don't work for you, create your own. Or try to find something else: http://bit.ly/14LMEL7[^].

—SA
 
Share this answer
 
Comments
sahrarainmelody 26-Sep-13 14:00pm    
totally my question is cheking email address by java script .I try some way by all of them have problems and don't work correctly . I have no idea any more .
Sergey Alexandrovich Kryukov 26-Sep-13 15:21pm    
There is no such thing as "Java script". Java is not a scripting language ;-). If you mean "JavaScript" it has nothing to do with "Java".
I do understand your question. After all, don't fix available expressions, write your own from scratch, to learn how to do it.
—SA
sahrarainmelody 27-Sep-13 2:25am    
if I could and had enough time I didn't ask ... thanks by the way
Sergey Alexandrovich Kryukov 27-Sep-13 3:02am    
You are welcome.
But... time?! why do you think that others have more time to help you then yourself?
—SA
sahrarainmelody 27-Sep-13 5:10am    
come on man !! I didn't think so .it's just a help request you can help if you want or can ignore ...thank you for your time and useful comments

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900