Validate Email by Javascript then link to next page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thupham
    New Member
    • Oct 2007
    • 28

    Validate Email by Javascript then link to next page

    I have 2 page:
    index.aspx
    next.aspx
    and the code in javascript to validate Email:
    Code:
    function fnEmail() 
    		{ 	
    			if(checkEmail(form1.txtEmail.value)== false) 
    			{
    				alert("Email is not valid!");
    				form1.txtEmail.focus();
    				return false;
    			} 
    			return true; 
    		} 
    		 function checkEmail(mail)
    		{
    			mail = trim(mail);
    			var re=/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,4}$/
    			if(mail.match(re) == null)
    				return false;
    			return true;
    		}
    		function trim(sString) 
    		{
    			while (sString.substring(0,1) == ' ') 
    			{
    				sString = sString.substring(1, sString.length);
    			}
    			while (sString.substring(sString.length-1, sString.length) == ' ')
    			{
    				sString = sString.substring(0,sString.length-1);
    			}
    			return sString;
    		}
    
    and the <input>:
    <a id="linknext" href="next.html"><input type="button" onclick="return         fnEmail();" class="NextButton" width="56" height="27"
    																					style="WIDTH: 56px; HEIGHT: 27px"> </a>
    When you click in button, I want to test email valid then link to next.aspx page,
    but It's not test validate and link to next.aspx? I don't know why and how to fix this bug.
    Can you help me for the purpose: testing email and link to next.aspx page?.
    Thanks
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Here is an example that may help:
    JavaScript RegExp Example: Regular Expression Tester

    Comment

    • thupham
      New Member
      • Oct 2007
      • 28

      #3
      Thanks for your reply but the link before is only submit the content and not link to next page. You can see in example before, the <input> tag was nested in <a> tag:
      <a href="next.aspx "><input type="submit" onclick="return fnEmail()"></input></a> Can you search more web you know about this problem for me?.
      Thanks.
      Last edited by thupham; Jan 11 '08, 01:53 AM. Reason: link

      Comment

      • CyberSoftHari
        Recognized Expert Contributor
        • Sep 2007
        • 488

        #4
        Subscribing …

        Comment

        • kunal pawar
          Contributor
          • Oct 2007
          • 297

          #5
          Modify ur Code, this will hepl you

          function fnEmail()
          {
          if(checkEmail(f orm1.txtEmail.v alue)== false)
          {
          alert("Email is not valid!");
          form1.txtEmail. focus();
          return false;
          }
          document.form Name.action="ne xt.html";
          document.submit ();
          return true;
          }
          function checkEmail(mail )
          {
          mail = trim(mail);
          var re=/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,4}$/
          if(mail.match(r e) == null)
          return false;
          return true;
          }
          function trim(sString)
          {
          while (sString.substr ing(0,1) == ' ')
          {
          sString = sString.substri ng(1, sString.length) ;
          }
          while (sString.substr ing(sString.len gth-1, sString.length) == ' ')
          {
          sString = sString.substri ng(0,sString.le ngth-1);
          }
          return sString;
          }

          and the <input>:
          <input type="button" onclick="return fnEmail();" class="NextButt on" width="56" height="27"
          style="WIDTH: 56px; HEIGHT: 27px">

          Comment

          Working...