Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question textarea validation to allow spaces

    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?

    Code:
    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;
    			}

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,016
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    In fact spaces are allowed:-

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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •