I've got a function which almost works - it validates an email address format in the following form:
It doesn't work at the moment because I don't know how to correctly insert a variable that accepts any string that the user inputs - how can this be achieved?
I am not going to profess to being an email validation expert.
If you really must not use regex, could do something along the lines of:
function validateEmail(str){
var index_at= str.indexOf('@')
if( index_at === -1){
return false;
}
var name= str.substr(0,index_at);
/* should test name for other invalids*/
var domain=str.substr(index_at+1);
/* should check for extra "@" and any other checks that would invalidate an address of which there are likely many*/
if( domain.indexOf('@') !=-1){
return false;
}
/* dot can't be first character of domain*/
return domain.indexOf('.') >0;
}
DEMO: http://jsfiddle.net/v43Hw/
Strongly recommend using a regex that has been tested against email standards for greater reliability.