Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
if (document.ff.ref1email.value != "")
{
var str = new String(document.ff.ref1email.value);
var isOK = true;
rExp = /[!\"£$%\^&*()-+=<>,\'#?\\|¬`\/\[\]]/
if( rExp.test(str) )
isOK = false;
if( str.indexOf('.') == -1 || str.indexOf('\@') == -1 )
isOK = false;
if( str.slice(str.lastIndexOf('.')+1,str.length).length < 2 )
isOK = false;
if( str.slice(0,str.indexOf('\@')).length < 1 )
isOK = false;
if( str.slice(str.indexOf('\@')+1,str.lastIndexOf('.')).length < 1 )
isOK = false;
if( !isOK )
alert( "Invalid email address - Reference One" );
return isOK;
}
if (document.ff.ref1email.value != "")
{
var str = new String(document.ff.ref1email.value);
var isOK = true;
rExp = /[!\"£$%\^&*()-+=<>,\'#?\\|¬`\/\[\]]/
if( rExp.test(str) )
isOK = false;
if( str.indexOf('.') == -1 || str.indexOf('\@') == -1 )
isOK = false;
if( str.slice(str.lastIndexOf('.')+1,str.length).length < 2 )
isOK = false;
if( str.slice(0,str.indexOf('\@')).length < 1 )
isOK = false;
if( str.slice(str.indexOf('\@')+1,str.lastIndexOf('.')).length < 1 )
isOK = false;
if( !isOK )
alert( "Invalid email address - Reference One" );
return isOK;
}
if (document.ff.ref1email.value != "")
{
var str = new String(document.ff.ref1email.value);
var isOK = true;
rExp = /[!\"£$%\^&*()-+=<>,\'#?\\|¬`\/\[\]]/
if( rExp.test(str) )
isOK = false;
if( str.indexOf('.') == -1 || str.indexOf('\@') == -1 )
isOK = false;
if( str.slice(str.lastIndexOf('.')+1,str.length).length < 2 )
isOK = false;
if( str.slice(0,str.indexOf('\@')).length < 1 )
isOK = false;
if( str.slice(str.indexOf('\@')+1,str.lastIndexOf('.')).length < 1 )
isOK = false;
if( !isOK )
alert( "Invalid email address - Reference One" );
return isOK;
}
if (document.ff.ref2email.value != "")
{
var str = new String(document.ff.ref2email.value);
var isOK = true;
rExp = /[!\"£$%\^&*()-+=<>,\'#?\\|¬`\/\[\]]/
if( rExp.test(str) )
isOK = false;
if( str.indexOf('.') == -1 || str.indexOf('\@') == -1 )
isOK = false;
if( str.slice(str.lastIndexOf('.')+1,str.length).length < 2 )
isOK = false;
if( str.slice(0,str.indexOf('\@')).length < 1 )
isOK = false;
if( str.slice(str.indexOf('\@')+1,str.lastIndexOf('.')).length < 1 )
isOK = false;
if( !isOK )
alert( "Invalid email address - Reference Two" );
return isOK;
}
And you say 1 works and the other doesn't. That's curious. I suggest you follow feherke's suggestion and pass the field name as an argument to a single function.
[b]function[/b] [COLOR=darkgoldenrod]checkemail[/color][teal]([/teal]what[teal])[/teal]
[teal]{[/teal]
[b]return[/b] [teal]![/teal] [teal]([/teal]
what [teal]==[/teal] [green][i]""[/i][/green]
[teal]||[/teal] [fuchsia]/[!\"£$%\^&*()-+=<>,\'#?\\|¬`\/\[\]]/[/fuchsia][teal].[/teal][COLOR=darkgoldenrod]test[/color][teal]([/teal]what[teal])[/teal]
[teal]||[/teal] what[teal].[/teal][COLOR=darkgoldenrod]indexOf[/color][teal]([/teal][green][i]'.'[/i][/green][teal])[/teal] [teal]==[/teal] [teal]-[/teal][purple]1[/purple]
[teal]||[/teal] what[teal].[/teal][COLOR=darkgoldenrod]indexOf[/color][teal]([/teal][green][i]'@'[/i][/green][teal])[/teal] [teal]==[/teal] [teal]-[/teal][purple]1[/purple]
[teal]||[/teal] what[teal].[/teal][COLOR=darkgoldenrod]slice[/color][teal]([/teal]what[teal].[/teal][COLOR=darkgoldenrod]lastIndexOf[/color][teal]([/teal][green][i]'.'[/i][/green][teal])+[/teal][purple]1[/purple][teal],[/teal]what[teal].[/teal]length[teal]).[/teal]length [teal]<[/teal] [purple]2[/purple]
[teal]||[/teal] what[teal].[/teal][COLOR=darkgoldenrod]slice[/color][teal]([/teal][purple]0[/purple][teal],[/teal]what[teal].[/teal][COLOR=darkgoldenrod]indexOf[/color][teal]([/teal][green][i]'@'[/i][/green][teal])).[/teal]length [teal]<[/teal] [purple]1[/purple]
[teal]||[/teal] what[teal].[/teal][COLOR=darkgoldenrod]slice[/color][teal]([/teal]what[teal].[/teal][COLOR=darkgoldenrod]indexOf[/color][teal]([/teal][green][i]'@'[/i][/green][teal])+[/teal][purple]1[/purple][teal],[/teal]what[teal].[/teal][COLOR=darkgoldenrod]lastIndexOf[/color][teal]([/teal][green][i]'.'[/i][/green][teal])).[/teal]length [teal]<[/teal] [purple]1[/purple]
[teal])[/teal]
[teal]}[/teal]
[b]function[/b] [COLOR=darkgoldenrod]validate[/color][teal]([/teal]form[teal])[/teal]
[teal]{[/teal]
[b]var[/b] error[teal]=[/teal]
[teal]([/teal][COLOR=darkgoldenrod]checkemail[/color][teal]([/teal]form[teal].[/teal]ref1email[teal].[/teal]value[teal])?[/teal][green][i]''[/i][/green][teal]:[/teal][green][i]'[/i][/green][lime][i]\n[/i][/lime][green][i]Invalid email address - Reference One'[/i][/green][teal])[/teal]
[teal]+[/teal] [teal]([/teal][COLOR=darkgoldenrod]checkemail[/color][teal]([/teal]form[teal].[/teal]ref2email[teal].[/teal]value[teal])?[/teal][green][i]''[/i][/green][teal]:[/teal][green][i]'[/i][/green][lime][i]\n[/i][/lime][green][i]Invalid email address - Reference Two'[/i][/green][teal])[/teal]
[b]if[/b] [teal]([/teal]error[teal])[/teal] [COLOR=darkgoldenrod]alert[/color][teal]([/teal][green][i]'Error occurred :'[/i][/green][teal]+[/teal]error[teal])[/teal]
[b]return[/b] [teal]![/teal]error
[teal]}[/teal]
[b]<form[/b] [maroon]action[/maroon][teal]=[/teal][green][i]"#"[/i][/green] [maroon]onsubmit[/maroon][teal]=[/teal][green][i]"return validate(this)"[/i][/green][b]>[/b]
[gray]<!-- ... -->[/gray]
[b]</form>[/b]
[b]function[/b] [COLOR=darkgoldenrod]validate[/color][teal]([/teal]form[teal])[/teal]
[teal]{[/teal]
[b]var[/b] error[teal]=[/teal]
[teal]([/teal][COLOR=darkgoldenrod]checkemail[/color][teal]([/teal]form[teal].[/teal]ref1email[teal].[/teal]value[teal])?[/teal][green][i]''[/i][/green][teal]:[/teal][green][i]'[/i][/green][lime][i]\n[/i][/lime][green][i]Invalid email address - Reference One'[/i][/green][teal])[/teal]
[teal]+[/teal] [teal]([/teal][COLOR=darkgoldenrod]checkemail[/color][teal]([/teal]form[teal].[/teal]ref2email[teal].[/teal]value[teal])?[/teal][green][i]''[/i][/green][teal]:[/teal][green][i]'[/i][/green][lime][i]\n[/i][/lime][green][i]Invalid email address - Reference Two'[/i][/green][teal])[/teal]
[highlight][teal]+[/teal] [teal]([/teal][COLOR=darkgoldenrod]checkemail[/color][teal]([/teal]form[teal].[/teal]ref3email[teal].[/teal]value[teal])?[/teal][green][i]''[/i][/green][teal]:[/teal][green][i]'[/i][/green][lime][i]\n[/i][/lime][green][i]Invalid email address - Reference Three'[/i][/green][teal])[/teal][/highlight]
[highlight pink][teal]+[/teal] [teal]([/teal][COLOR=darkgoldenrod]checkssn[/color][teal]([/teal]form[teal].[/teal]ssn[teal].[/teal]value[teal])?[/teal][green][i]''[/i][/green][teal]:[/teal][green][i]'[/i][/green][lime][i]\n[/i][/lime][green][i]Invalid social security number - Wrong format'[/i][/green][teal])[/teal][/highlight]
[highlight paleturquoise][teal]+[/teal] [teal]([/teal]form[teal].[/teal]thename[teal].[/teal]value[teal]?[/teal][green][i]''[/i][/green][teal]:[/teal][green][i]'[/i][/green][lime][i]\n[/i][/lime][green][i]Invalid name - Can not be empty'[/i][/green][teal])[/teal][/highlight]
[highlight paleturquoise][teal]+[/teal] [teal](![/teal]form[teal].[/teal]age[teal].[/teal]value[teal].[/teal][COLOR=darkgoldenrod]match[/color][teal]([/teal][fuchsia]/\D/[/fuchsia][teal])?[/teal][green][i]''[/i][/green][teal]:[/teal][green][i]'[/i][/green][lime][i]\n[/i][/lime][green][i]Invalid age - Contains non-digits'[/i][/green][teal])[/teal][/highlight]
[highlight paleturquoise][teal]+[/teal] [teal]([/teal]form[teal].[/teal]address[teal].[/teal]value[teal].[/teal]length[teal]>=[/teal][purple]10[/purple][teal]?[/teal][green][i]''[/i][/green][teal]:[/teal][green][i]'[/i][/green][lime][i]\n[/i][/lime][green][i]Invalid address - Too short'[/i][/green][teal])[/teal][/highlight]
[b]if[/b] [teal]([/teal]error[teal])[/teal] [COLOR=darkgoldenrod]alert[/color][teal]([/teal][green][i]'Error occurred :'[/i][/green][teal]+[/teal]error[teal])[/teal]
[b]return[/b] [teal]![/teal]error
[teal]}[/teal]
function checkemail(what)
{
return ! (
what == ""
|| /[!\"£$%\^&*()-+=<>,\'#?\\|¬`\/\[\]]/.test(what)
|| what.indexOf('.') == -1
|| what.indexOf('@') == -1
|| what.slice(what.lastIndexOf('.')+1,what.length).length < 2
|| what.slice(0,what.indexOf('@')).length < 1
|| what.slice(what.indexOf('@')+1,what.lastIndexOf('.')).length < 1
)
}
var error=
(checkemail(document.ff.staffsupporteremail.value))
if (error) {
alert("Error occurred");
return false;
}
[b]var[/b] error[teal]=[highlight]![/highlight][/teal][COLOR=darkgoldenrod]checkemail[/color][teal]([/teal]document[teal].[/teal]ff[teal].[/teal]staffsupporteremail[teal].[/teal]value[teal])[/teal]