topical media & game development
#javascript-code-08-rules.js / js
var errMsg = {
// Checks for when a specified field is required
required: {
msg: "This field is required.",
test: function(obj,load) {
// Make sure that something was not entered and that this
// isn't on page load (showing 'field required' messages
// would be annoying on page load)
return obj.value || load || obj.value == obj.defaultValue;
}
},
// Makes sure that the field s a valid email address
email: {
msg: "Not a valid email address.",
test: function(obj) {
// Make sure that something was entered and that it looks like
// an email address
return !obj.value ||
/^[a-z0-9_+.-]+\@([a-z0-9-]+\.)+[a-z0-9]{2,4}/.test(obj.value);
}
},
// Makes sure that the field is a valid URL
url: {
msg: "Not a valid URL.",
test: function(obj) {
// Make sure that some text was entered, and that it's
// not the default http:// text
return !obj.value || obj.value == 'http://' ||
// Make sure that it looks like a valid URL
/^https?:\/\/([a-z0-9-]+\.)+[a-z0-9]{2,4}.*
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.