SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    May 2010
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Input Validation Help

    I am very new to Javascript. I need to validate some input on an existing PHP/MySQL application.

    I have this:

    function validateform() {
    if (doc.drop.value.length < 1) {
    alert("Please enter a value for the drop.");
    return false;
    }
    }

    That makes sure its not empty. But I also need to make sure it only contains a-z A-Z 0-9 and also allow spaces underscores"_" and dashes"-" but thats it. I am sure there is a simple solution to this but I am new to javascript.

    Thanks.

    Matthew

  2. #2
    SitePoint Zealot
    Join Date
    May 2009
    Location
    Netherlands
    Posts
    189
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    if (!/^[\w -]+$/.test(doc.drop.value)) {
    http://www.javascriptkit.com/jsref/regexp.shtml


Bookmarks

Posting Permissions

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