Hello,
I have written a javascript function for email validation . On the click event of the validate button am calling the function however, the function is not called and returns nothing....so please help me out....plz help me out and do let me know where am going wrong...!
here is the function and code behind :

In the source i have written :

<script language="javascript">
<script language = "Javascript">
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}
</script>

In the code behind i have written :

protected void btnvalidate_Click(object sender, EventArgs e)
    {
        txtemail.Attributes.Add("Onclick", "javascript:echeck();");
    }

PLZ HELP ME OUT....WHERE AM I GOING WRONG ? FUNCTION DOES NOT GET CALLED ON THE CLICK OF THE VALIDATE BUTTON !

CYA
ROHAN

Recommended Answers

All 4 Replies

laghaterohan,
You should have to post in ASP.NET forum. echeck() require an argument.

protected void btnvalidate_Click(object sender, EventArgs e){
        txtemail.Attributes.Add("onclick", "echeck('Something');");
  }

oh sorry....i ll do d needful....

btw its not working even after supplying the argument!

cya
Rohan

oh sorry....i ll do d needful....

btw its not working even after supplying the argument!

cya
Rohan

Problem with javascript block.

<script language = "Javascript">
 function echeck(str) {
 }
</script>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.