Hi,
I have a problem with validating email in javascript. I can do this in PHP but I have to use javascript for this and I am not a javascript expert.
I am modifying an existing script and that has an email validation function. This works for most parts of validating an email but where it falls down is, when a user doesn't enter the .com (etc.) after the email ie: the current script lets them enter me@mysite where it should be me@mysite.com
Can someone help me with adding a check to the function below, that will ensure a user enters a text, a . and then more text after the @ symbol.
Thanks
Here is how it looks at the moment:
Thanks in advance,Code:function chkEmail(txt) { if (!txt || txt.length < 1) { OT_ErrAdd("You must enter an email address\n"); return false; } i = txt.indexOf('@'); if (i < 0) { OT_ErrAdd("Your email address must contain an '@' symbol\n"); return false; } else if (i == 0) { OT_ErrAdd("Your email address cannot start with the '@' symbol\n"); return false; } else if (i == txt.length-1) { OT_ErrAdd("Your email address cannot end with the '@' symbol\n"); return false; } i = txt.indexOf('@', i+1); if (i != -1) { OT_ErrAdd("Your email address must contain only one '@' symbol\n"); return false; } }
Martin




Bookmarks