Script correction for validating email text field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • coder10
    New Member
    • Mar 2010
    • 3

    Script correction for validating email text field

    Hi,
    Can anyone make me understand in JavaScript what is all which are in bold, I need simple function to validate a text-field on a form that is to hold an email address. The below in bold is complex for me to understand. Please make correction or provide new function.

    Code:
    <script type="text/javascript">	
    	
    		function validateEmail(Form) 
    		{
    		[B]if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(Form.emailAddr.value))[/B]
    		{
    		alert("Valid Email Address");
    		return (true)
    		}
    		alert("Invalid E-mail Address!")
    		return (false)
    		}  
    	//-->
    	</script>
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    that’s one of the simpler email RegExp that the input is tested against

    Comment

    • coder10
      New Member
      • Mar 2010
      • 3

      #3
      Thanks for the reply, i hope that is Javascript right? i found script from w3school as follows
      What is the difference between the earlier one and this one,
      Code:
      <script type="text/javascript">
      function validate_email(field,alerttxt)
      {
      with (field)
        {
        apos=value.indexOf("@");
        dotpos=value.lastIndexOf(".");
        if (apos<1||dotpos-apos<2)
          {alert(alerttxt);return false;}
        else {return true;}
        }
      }
      
      function validate_form(thisform)
      {
      with (thisform)
        {
        if (validate_email(email,"Not a valid e-mail address!")==false)
          {email.focus();return false;}
        }
      }
      </script>
      </head>

      Comment

      Working...