Removing unwanted characters

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Phil Amey

    Removing unwanted characters

    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.v alue == ""){
    alert("Please complete the Project Title: field")
    document.form1. ProjectTitle.fo cus()
    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



  • kaeli

    #2
    Re: Removing unwanted characters

    In article <4003E175.5A5E2 325@btinternet. com>, philamey@btinte rnet.com
    enlightened us with...[color=blue]
    > 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.v alue == ""){
    > alert("Please complete the Project Title: field")
    > document.form1. ProjectTitle.fo cus()
    > 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
    >
    >
    >
    >[/color]

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

    function checkAlphanumSp ecial(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(strObje ct)) return false;
    if (!re.test(strOb ject.value)) return false;
    else return true;
    }

    if (!checkAlphanum Special(documen t.form1.Project Title)){

    --
    --
    ~kaeli~
    Once you've seen one shopping center, you've seen a mall.



    Comment

    Working...