Removing unwanted characters

P

Phil Amey

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
 
K

kaeli

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)){

--
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top