Home > 2010 Summer BTI220 > User input validation with JavaScript RegEx

User input validation with JavaScript RegEx


In assignment 2, you are asked to validate user input. This post will help you do that.

.

Learning about user input validation

The new textbook covers JavaScript regular expressions at an introductory level.

If you don’t have the textbook, the following tutorial is pretty good:

Introductory Guide to regular expressions
.

Recommended approach

The JavaScript code to validate user input can be added to the beginning “add a new comment” button click function. If the user input validates, you can continue adding the data to the table.

Create a regular expression object for each <input> element that needs validation.

Create a boolean object to keep track of validation state, and set its initial state to false.

Set the boolean object to the result of the regular expression object’s “test” message to validate the <input> element’s text (i.e. document.GetElementById(‘userInput’).value). Repeat for every <input> element that you want to validate.

If the boolean object is true, then you can continue by adding the data to the table. Otherwise, notify the user.

.


Advertisements
Categories: 2010 Summer BTI220
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: