- Impact
- 1
This code will validate an email address to ensure the user enters an email address in the correct format:
<script Language="Javascript">
<!--
function checkform(theform){
var EmailOk = true
var Temp = theform.email
var AtSym = Temp.value.indexOf('@')
var Period = Temp.value.lastIndexOf('.')
var Space = Temp.value.indexOf(' ')
var Length = Temp.value.length - 1
if ((AtSym < 1) ||
(Period <= AtSym+1) ||
(Period == Length ) ||
(Space != -1)){
EmailOk = false
alert('Please enter a valid e-mail address!')
theform.email.focus();
return (false);}
}
//-->
</script>
Example form code:
<form method=" POST" action="/success.htm" onsubmit="return checkform(this)" name="myform">
When this form is submitted, the javascript runs and will only go to '/success.htm' if user enters a correctly formatted email address.
If the user does not enter a correctly formatted email address, a pop up alert box appears to let them know.
<script Language="Javascript">
<!--
function checkform(theform){
var EmailOk = true
var Temp = theform.email
var AtSym = Temp.value.indexOf('@')
var Period = Temp.value.lastIndexOf('.')
var Space = Temp.value.indexOf(' ')
var Length = Temp.value.length - 1
if ((AtSym < 1) ||
(Period <= AtSym+1) ||
(Period == Length ) ||
(Space != -1)){
EmailOk = false
alert('Please enter a valid e-mail address!')
theform.email.focus();
return (false);}
}
//-->
</script>
Example form code:
<form method=" POST" action="/success.htm" onsubmit="return checkform(this)" name="myform">
When this form is submitted, the javascript runs and will only go to '/success.htm' if user enters a correctly formatted email address.
If the user does not enter a correctly formatted email address, a pop up alert box appears to let them know.
Last edited: