Click to See Complete Forum and Search --> : Form validation (first steps)


Cesark
11-06-2003, 12:58 PM
Hi!

I am learning how to validate a form and I need some aid. First I should understand what does (src="file.js”) mean, how it works and where I have to write it. And second I will begin with the ‘e-mail validation’.

I attached an example of e-mail validation that works without (src=”file.js”). The function code here should be the same of the function code written in the (file.js)?

Thanks,
Cesar

Charles
11-06-2003, 01:11 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>

<style type="text/css">
<!--
label {display:block; margin:1em 0em}
input {display:block}
-->
</style>

<script type="text/javascript">
<!--
String.prototype.isEmailAddress = function () {return this.match(/^[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+(?:\.[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+)*\@[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+(?:\.[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+)+$/)}
// -->
</script>

<form action="">
<div>
<label>Email Address<input type="text" onchange="if (!this.value.isEmailAddress()) {alert ('That would not appear to be a valid email address.'); this.value=''; this.focus()}"></label>
<button type="submit">Submit</button>
</div>
</form>

Cesark
11-06-2003, 01:26 PM
This way is more useful than my attached?

What about (src="file.js”) ?

Charles
11-06-2003, 01:37 PM
Your attached wasn't salvageable, but see http://www.w3.org/TR/html4/interact/scripts.html#h-18.2.1 for the answer to your other question.

Cesark
11-07-2003, 03:31 AM
Ok, thank you