Tech Thought

Tech tips, hints, and general musings. PHP, Perl, Mysql, Javascript, AJAX, JSON, Linux, Mac OSX

Entries for February 5th, 2008

Javascript validation of Email Address, Numeric Values and an Input Mask for Numbers Only

A couple of very simple yet handy routines for validation of form fields: Function to validate an email address (see original post): function ValidateEmail(email){ var emailReg = “^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$”; var regex = new RegExp(emailReg); return regex.test(email); } Function to validate a number: function ValidateNumber(num) { return num.match(/^\d+$/); } Input mask for a field to only accept [...]

Comments (2)

Creating Objects with Javascript

Recently I’ve started overhauling all our old javascript libraries to make them more object-based and easier to maintain. As a result, I’ve needed to get familiar with how to create objects and assign properties and methods. This is surprisingly easy in javascript: Creating an object (Constructor) with properties: function MyObject(param1, param2) { this.myProperty = param1; [...]

Leave a Comment