tags:

views:

831

answers:

2
function validation(reg) {
    str = document.reg;
    if (str.name.value == "") {
        alert("Enter your name");
        str.name.focus();
        return false;
    }

Validation will working fine if input is empty.

Problem

  1. User can enter a blank space on the first.
  2. Also user can enter space only on the name.

How to prevent it?

+1  A: 

Here are some trim functions.

http://www.somacon.com/p355.php

and using it

function validation(reg) {
    str = document.reg;
    if (str.name.value.trim() == "") {
        alert("Enter your name");
        str.name.focus();
        return false;
    }
Daniel A. White
thanks Daniel fixed now :) cool!
bob
No problem bob.
Daniel A. White
A: 

Another possibility is to use this test instead:

if (!s.match(/\w/)) {
  // ohnoes
}
wombleton