i want to perform validation on the E-mail cell, when u dont type emails correctly to give the warning on the right side of the box "ERROR: not a valid e-mail address" or something..
// --------------------------------------------
// validateEmail
// Validate if e-mail address
// Returns true if so (and also if could not be executed because of old browser)
//
function validateEmail (
valfield, // element to be validated
infofield, // id of element to receive info/error msg
required) // true if required
{
var stat = commonCheck (valfield, infofield, required);
if (stat != proceed) return stat;
var tfld = trim(valfield.value); //whitespace trimmed off
var email = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
if (!email.test(tfld)) {
msg (infofield, "error", "ERROR: not a valid e-mail address");
setfocus(valfield);
return false;
}
var email2 = /^[A-Za-z][\w.-]+@\w[\w.-]+\.[\w.-]*[A-Za-z][A-Za-z]$/ ;
if (!email2.test(tfld))
msg (infofield, "warn", "Unusual e-mail address - check if correct");
else
msg (infofield, "warn", "OK");
return true;
}
my problem is that this doesnt work.. i think the problem is on this specific part onsubmit="return validateEmail()"
Edit: i want to mention that i want to "Live"-validate the email box, when u type the mail for example and u type telisgmail.com instead of telis@gmail.com or simply telis, the moment u press tab, or click somewhere out of the cell , if the email has not the correct form, the error msg must appear on the right. how do i do this?
i think i must not use onsubmit to achieve this.. any help will be appreciated. thanks in advance.
// --------------------------------------------
// validateEmail
// Validate if e-mail address
// Returns true if so (and also if could not be executed because of old browser)
//
function validateEmail (
valfield, // element to be validated
infofield, // id of element to receive info/error msg
required) // true if required
{
var stat = commonCheck (valfield, infofield, required);
if (stat != proceed) return stat;
var tfld = trim(valfield.value); //whitespace trimmed off
var email = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
if (!email.test(tfld)) {
msg (infofield, "error", "ERROR: not a valid e-mail address");
setfocus(valfield);
return false;
}
var email2 = /^[A-Za-z][\w.-]+@\w[\w.-]+\.[\w.-]*[A-Za-z][A-Za-z]$/ ;
if (!email2.test(tfld))
msg (infofield, "warn", "Unusual e-mail address - check if correct");
else
msg (infofield, "warn", "OK");
return true;
}
Bookmarks