...

View Full Version : textarea validation to allow spaces



tranquilraven
08-31-2007, 05:59 PM
Hello,

I have a textarea validation that I am trying to get to allow only certain characters (to avoid hyperlinks being placed in my comments box), but for some reason the code below will not allow spaces. Any suggestions?



case "nohyper":
{
var charpos = objValue.value.search("[^\sA-Za-z0-9\-_]");
if(objValue.value.length > 0 && charpos >= 0)
{
if(!strError || strError.length ==0)
{
strError = objValue.name+": characters allowed are A-Z,a-z,0-9,- and _";
}//if
alert(strError + "\n [Error character position " + eval(charpos+1)+"]");
return false;
}//if
break;
}

Philip M
09-03-2007, 07:30 AM
In fact spaces are allowed:-

var charpos = objValue.value.search("[^ \s A-Za-z0-9\-_]");



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum