Removing unwanted characters

Discussion in 'Javascript' started by Phil Amey, Jan 13, 2004.

  1. Phil Amey

    Phil Amey Guest

    In a web based form I am able to make sure that there is text in an input field but I want to restrict the user from using such characters as ~
    # & '

    How can I modify this JavaScript below to enable this ?

    if (document.form1.ProjectTitle.value == ""){
    alert("Please complete the Project Title: field")
    document.form1.ProjectTitle.focus()
    validFlag = false
    return validFlag
    }

    When entering the project title into another system it issues an error when those characters are input - hence the need to delete them from the
    request

    Kindest Regards - Philip Amey
    Phil Amey, Jan 13, 2004
    #1
    1. Advertising

  2. Phil Amey

    kaeli Guest

    In article <>,
    enlightened us with...
    > In a web based form I am able to make sure that there is text in an input field but I want to restrict the user from using such characters as ~
    > # & '
    >
    > How can I modify this JavaScript below to enable this ?
    >
    > if (document.form1.ProjectTitle.value == ""){
    > alert("Please complete the Project Title: field")
    > document.form1.ProjectTitle.focus()
    > validFlag = false
    > return validFlag
    > }
    >
    > When entering the project title into another system it issues an error when those characters are input - hence the need to delete them from the
    > request
    >
    > Kindest Regards - Philip Amey
    >
    >
    >
    >


    Here's my function. Modify it to include the characters you like.
    Characters listed in the variable "re" are ALLOWED.

    function checkAlphanumSpecial(strObject)
    {
    /* Returns true if the field has all alphanumeric characters and some
    special chars,
    plus whitespace, false if not.
    You must pass in a input (text) object, not the value. */
    var re = /^[A-Za-z0-9,.:()]+$/;

    if (!strObject || isBlank(strObject)) return false;
    if (!re.test(strObject.value)) return false;
    else return true;
    }

    if (!checkAlphanumSpecial(document.form1.ProjectTitle)){

    --
    --
    ~kaeli~
    Once you've seen one shopping center, you've seen a mall.
    http://www.ipwebdesign.net/wildAtHeart
    http://www.ipwebdesign.net/kaelisSpace
    kaeli, Jan 13, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve
    Replies:
    7
    Views:
    5,782
    Steve
    Sep 18, 2005
  2. et
    Replies:
    3
    Views:
    719
  3. , India
    Replies:
    7
    Views:
    293
    Jorgen Grahn
    Aug 13, 2010
  4. Juo Hundred
    Replies:
    4
    Views:
    127
    Juo Hundred
    Jun 18, 2009
  5. Maxi

    Removing unwanted toolbars

    Maxi, Apr 5, 2006, in forum: Javascript
    Replies:
    5
    Views:
    101
    Thomas 'PointedEars' Lahn
    Apr 6, 2006
Loading...

Share This Page