Folder in the Trash

GIGO…Garbage In Garbage Out. This is a term that can sometimes be associated with data. Let’s face it, data is the lifeblood of any organization. In today’s marketplace, data analytics and data mining help organizations meet the needs of their clientele. So…that data needs to be protected to the utmost. This is where, as developers, we have a role to play.


Before I address the developer’s role, let’s chat about the database administrator’s (dba) role. It is their role to protect the data at all cost. Most good dba’s take this very seriously…and rightly so. As a developer, I sometimes don’t look at it that way and feel that it is a pain. “I mean, come on…just give me admin rights to the database and do a select asterisk so I can build cool apps!” I have said variations of this at times throughout my career. That quote is probably making dba’s skin crawl. They have a highly important job…let’s make it easier as developers. In comes data validation.

Data Validation Location

Data validation is performed in two main locations…server-side and client-side. I want to speak to the client-side in this post. This is the first line of defense and the easiest location to tend to things. Most data validation involves forms.

Let’s be real here…show of hands…how many of you have filled out a form, say a registration form, and put in bogus information just to get the form filled out and in the door? I thought so. Once that happens, the data is tainted. Developers can help prevent this.

There are two main ways to accomplish this…1) HTML constraints and 2) programmatic validation with JavaScript and Regular Expressions. I plan on addressing the coding side of things with regular expressions at a later date. For now, I want to speak to HTML constraints.

HTML Constraints

It can go a long way towards data validation when the proper HTML is used to build a form. Let’s say you are asking the end user for a date. HTML5 has a date input type field complete with drop down calendar! I recall building that by hand. That enhancement alone was worth the price of admission for me to HTML5. If the HTML is written with another input type, say a text field, well…you have opened the door to allow the end user to specify any date format they wish…which will lead to errors and possibly a knock on your door from your friendly. neighborhood dba.

Some examples of helpful HTML5 input types are:

  • search
  • email
  • url
  • tel
  • number
  • range
  • date
  • month
  • week
  • time
  • datetime
  • datetime-local
  • color

So make sure you select the proper HTML5 input types and constraints to make the rest of your validation easier.

Happy Coding!

Clay Hess

Forms…how do they work?

stop hand

In nearly every web application, you will build a form of some kind. There are a lot of moving parts with forms. So I thought I would spend a post discussing those parts…or at least parts of those parts.


So how does this whole form process work? At its basic level, it works as follows…

  1. End user submits the form
  2. Form is received by the web server
  3. Submission is passed to the app server (.NET, Java, PHP, etc.)
  4. App processes the form (validation, database interactions, etc.)

Now, that is an extremely high-level explanation. There are a lot of pieces that need to be in place for a form to work properly. Let me address each of these over several posts. Let’s begin with the first one…the end user submitting the form.

In the ‘old days’, HTML forms were submitted directly to the web server. This is no longer the case. As web developers, what we typically do is capture the form submission. In other words, we do not allow the form submission to occur as it normally would under regular HTML. We want to control the submission process to ensure it is completed properly. Typically, this involves validation (which I will write a more detailed validation post at a later date). We want to make certain that our data is correct and we do not get

We want to make certain that our data is correct and we do not get ‘GIGO’, or Garbage In, Garbage Out. Data is the life-blood of an organization. So we want to ensure it is as clean as possible. This may be checking that the data is in the format required, that there is data in the form fields at all, etc.

So, nowadays, we grab the submission event and stop it. We then run the form data through several validation checks, give whatever feedback is necessary and submit the form on behalf of the end user.

There are several ways to stop the regular form submission process. Some of these depend on the framework that is being used. Allow me to offer just some examples of how a developer might do this…

I, personally, prefer the first two methods of using preventDefault(). This separates the functionality from the content.

Happy Coding!

Clay Hess

Round and Round

math functions

Math…I know…some of you are letting our a collective groan. Let’s face it, not all of us like math, but it is necessary and can be very helpful in developing applications. Fortunately, JavaScript has some built in Math methods to assist us.

  • PI – returns 3.14….
  • round() – round floating point to nearest integer
  • floor() – round floating point down
  • ceil() – round floating point up
  • random() – generate random number between 0 and 1

There is also, min(), max() and abs(), which returns an absolute number.

So if you need to perform any of these mathematical calculations, let the JavaScript engine do it for you.

Note: If you want a random number between numbers other than 0 & 1, you can do that easily enough…

Happy Coding!

Clay Hess