Results 1 to 4 of 4

Thread: JavaScript for enter valid Email Id

  1. #1
    AdamsClark is offline Senior Member
    Join Date
    Dec 2009
    Posts
    247
    Rep Power
    3

    Default JavaScript for enter valid Email Id

    Hi. I am learning JavaScript language. I want to write JavaScript function for user enters valid Email-Id. If user enter email id in wrong format it will give error message. Your help would be greatly appreciated. Thanks in advanced.
    Last edited by nitesh14; 04-26-2010 at 03:52 AM.

  2. #2
    stevenbas is offline Member
    Join Date
    Apr 2010
    Posts
    25
    Rep Power
    0

    Default

    Try out this code, when you run this function you can check the user enter valid email id or not:
    Code:
    function checkEmailID(frmName,fldName)
    {
    	if  (!(isNull(eval("document."+frmName+"."+fldName+".value"))))
    	{
    		if (/^w+([.-]?w+)*@w+([.-]?w+)*(.w{2,3})+$/.test(eval("document."+frmName+"."+fldName+".value")))
    		{
    			return true;
    		} 
    		else
    		{
    			alert("Invalid E-mail ID! Please re-enter.");
    			eval("document."+frmName+"."+fldName+".focus()");
    			return false;
    		}
    	}
    	else
    	{
    		alert(" Please provide E-mail ID. ");
    		eval("document."+frmName+"."+fldName+".focus()");
    		return false;
    	}
    }

  3. #3
    montecarlos is offline Junior Member
    Join Date
    Apr 2010
    Posts
    23
    Rep Power
    0

    Default

    Refer following JavaScript for user enter valid email id:
    Code:
    function validate(form_id,email) 
    {
       var reg = /^([A-Za-z0-9_-.])+@ ([A-Za-z0-9_-.])+.([A-Za-z]{2,4})$/;
       var address = document.forms[form_id].elements[email].value;
       if(reg.test(address) == false) {
          alert('Invalid Email Address');
          return false;
       }
    }

  4. #4
    Davisricky is offline Senior Member
    Join Date
    Dec 2009
    Posts
    331
    Rep Power
    3

    Default

    If you are use asp.net then use following code. Hope this helps you out with your problem.

    Code:
    <asp:textbox id="txt_email" runat="server"/>
    <asp:RegularExpressionValidator id="email_valid" runat="server"
        ControlToValidate="txt_email"
        ValidationExpression=".*@.*..*"
        ErrorMessage="* Enter Valid Email-Id."
        display="dynamic">
    </asp:RegularExpressionValidator>

Similar Threads

  1. JavaScript for user enter only number.
    By allister fisher in forum Programming
    Replies: 2
    Last Post: 07-30-2010, 09:31 PM
  2. JavaScript for enter only characters
    By LewisClark in forum Programming
    Replies: 2
    Last Post: 05-03-2010, 02:04 PM
  3. JavaScript for enter only number.
    By BellWard in forum Programming
    Replies: 4
    Last Post: 04-29-2010, 01:12 PM
  4. Games: Error message: Not a Valid Win32 Application
    By Anne Bancroft in forum Windows Vista
    Replies: 0
    Last Post: 10-06-2009, 11:27 AM
  5. CO can enter a hotmail email
    By Abel789 in forum General Internet Terms
    Replies: 2
    Last Post: 04-27-2009, 08:34 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
SEO by SubmitEdge

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48