326
If you look in the online examples, you’ll nd a folder called
chapter05-interlude/breakneck. This has all the Break Neck
les, as well as a new utility le, validation-utils.js. Here’s
how you can add validation to your local version of Break Neck Pizza:
Protecting against SQL injection
in your JavaScript
Make sure you have validation-utils.js
1
Add a reference to validation-utils.js in
the Break Neck web form.
2
return (isInteger(s) &&
s.length >= minDigitsInIPhoneNumber);
}
function validatePhone(phoneNumber) {
if ((phoneNumber == null) || (phoneNumber == “”)) {
alert(“Please enter your phone number.”);
return false;
validation-utils.js
<script>
var request...
function
createRequest()
{
...
}
</script>
Here’s just part of the validation-utils.js
le. This le is in the examples, in the
chapter05-interlude/breakneck/ folder.
validatePhone() is the
function you’ll use to
check the phone numbers
entered in the Break
Neck web form.
<html>
<head>
<title>The New and Improved Break Neck Pizza</title>
<link rel=”stylesheet” type=”text/css”
href=”breakneck.css” media=”screen” />
<script type=”text/javascript” src=”ajax.js”> </script>
<script type=”text/javascript” src=”pizza.js”> </script>
<script type=”text/javascript”
src=”validation-utils.js”> </script>
</head>
<html>
.
.
.
</html>
This line makes the
functions in validation-
utils.js available to the
rest of your JavaScript.
Here’s the ...