Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Wildcards

Status
Not open for further replies.

faiyth

Programmer
Nov 22, 2002
19
US
What I'm trying to do is validate an entry that a user types in. I'm trying to use wildcards but I'm not sure how. I want to make sure that no commas, double quotes, and single quotes are in the text entered by the user. My database statement can't handle those entries so I need to keep them out. How do I do it in Javascript in a ASP document? Also how do I check for double quotes? What do I wrap around them to have them be seen as double quotes?

function validate()
{
bugtitle=document.f_bugedit.Title
bugdesc=document.f_bugedit.Description
bugbf=document.f_bugedit.BuildFixed
bugbr=document.f_bugedit.BuildReported
If ((bugtitle="*,*") || (bugtitle="*'*") || (bugdesc="*,*") || (bugdesc="*'*") || (bugbf="*,*") || (bugbf="*'*") || (bugbr="*,*") || (bugbr="*'*"))
{
alert("Please do not use any single quotes, double quotes or comma characters in your bug report. Thanks!")
}
}
 
you can escape double quotes eg. \" Regards

Big Bad Dave

davidbyng@hotmail.com
 
Hey!

I think you can modify this function I'm using
Itll check every input field in the form named 'form1'

function ValidateFields()
{
for(var i=0;i<document.form1.elements.length;i++)
{
var v = document.form1.elements;
if (v.type=='text' || v.type=='password')
{
var p = (v.value).indexOf('<');
var len = (v.value).length;
if (p >= 0 && p<= len)
return ErrorAlert(v);
p = (v.value).indexOf(&quot;>&quot;);
if (p >= 0 && p<= len)
return ErrorAlert(v);
p = (v.value).indexOf('#');
if (p >= 0 && p<= len)
return ErrorAlert(v);
p = (v.value).indexOf('&quot;');
if (p >= 0 && p<= len)
return ErrorAlert(v);
p = (v.value).indexOf(&quot;'&quot;);
if (p >= 0 && p<= len)
return ErrorAlert(v);
}
}
return true;
}

function ErrorAlert(elem)
{
alert(&quot;This input field cannot contain the following characters:\n\t \\ < > ' # \&quot;&quot;);
elem.focus();
return false;
}

Good luck
Ron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top