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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to format a string search

Status
Not open for further replies.

tiamat2012

Programmer
Joined
Dec 12, 2004
Messages
144
Location
US
Basically I'm doing a form validation, and allowing certain characters (that my client requested). Because he wants "s, -s and such, I've tried to use HTML entities, but its only working on the ampersand.

I've never learned the structure of how to write these and just picked it up and tried to edit them, and I don't know the name of what type of formatting it is so I don't know where to learn. Can anyone help me?

Code:
[blue]
var charpos = objValue.value.search("[^A-Za-z0-9\  &"-$.,'!#?()]");[/blue] 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
               if(!strError || strError.length ==0) 
                { 
                  strError = objValue.name+": Only alpha-numeric characters allowed "; 
                }//if 
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
              }//if 
              break;

Sincerely,
Kerry
 
Can you post the HTML code for your form here please? If you do, I think I'll be able to edit/fix that JavaScript code for you.


I hope this helps;
Rob Hercules
 
Oh, thank you! I figured it out after that, however, and found out it was <i>regular expression</i>.

I would still like to learn more about them as the tutorial I did wasn't the best, but allowed me to fix the problem I had, but I still don't feel comfortable with it, so if you have a place I could learn that would be great.

This is the code that ended up working:
Code:
var charpos = objValue.value.search("[^A-Za-z0-9\042\046\047\055\057\ $.,!#?()]");

Thank you very much,
Kerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top