www.webdeveloper.com
Results 1 to 4 of 4

Thread: Trim text for form validation

  1. #1
    Join Date
    Mar 2009
    Posts
    41

    Trim text for form validation

    Is there a way of trimming the value before checking it so that a space for example would still be NULL "".

    Cheers,

    Code:
    if(document.sendmail.emailsubject.value == '')
    {
        msg += "Subject cannot be left blank.\n";
        error = true;
    }

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654

  3. #3
    Join Date
    Mar 2009
    Posts
    41
    So I take it there is no nice and simple...

    if(document.sendmail.emailsubject.value.Trim() == '' )
    From the looks of it I need to put it in a variable and then use some regex?

    Cheers

  4. #4
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    The native function trim works in some browsers, but regex will also be required
    Last edited by Fang; 12-08-2010 at 03:23 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles