I am checking the email Id of the user during registration to it is valid or not I am using the Javascript.I am getting the value of the Textbox in the function during button click and verifying it but during click of the button it shows Microsoft JScript runtime error: Object required error Can any one point out what would be wrong in my code,
My javascript Function is,
var txt = document.getElementById("emailid").value;
if (txt != "") {
var at = "@"
var dot = "."
var lat = str.indexOf(at)
var lstr = str.length
var ldot = str.indexOf(dot)
if (txt.indexOf(at) == -1) {
alert("Invalid E-mail ID")
obj.focus()
return false
}
if (txt.indexOf(at) == -1 || txt.indexOf(at) == 0 || txt.indexOf(at) == ltxt) {
alert("Invalid E-mail ID")
obj.focus()
return false
}
if (txt.indexOf(dot) == -1 || txt.indexOf(dot) == 0 || txt.indexOf(dot) == lstr) {
alert("Invalid E-mail ID")
obj.focus()
return false
}
if (str.indexOf(at, (lat + 1)) != -1) {
alert("Invalid E-mail ID")
obj.focus()
return false
}
if (txt.substring(lat - 1, lat) == dot || txt.substring(lat + 1, lat + 2) == dot) {
alert("Invalid E-mail ID")
obj.focus()
return false
}
if (txt.indexOf(dot, (lat + 2)) == -1) {
alert("Invalid E-mail ID")
obj.focus()
return false
}
if (txt.indexOf(" ") != -1) {
alert("Invalid E-mail ID")
obj.focus()
return false
}
}
return true
}
Andrew Deniel
14-Oct-2013Check if your control is "runat=server" if so, the rendered html control name should be something like: #ctl00_ContentPlaceHolderMain_emailid.
Try changing this:
var txt = document.getElementById("emailid").value;
to this:
var txt = document.getElementById('<%=emailid.ClientID %>').value;
The ClientID will give you the full name in case the control is inside a content panel.
On the other side you are accessiong the property obj.focus()and I can't see obj declared inside the scope.