CoverYourASP --> Snippets |
| "Snippets" are mini-articles - they allow me to very quickly add answers to your frequently asked questions, and add brief explanations for topics that you've searched for without success. So, everytime you send an email or perform a search, chances are a new snippet will be the result!18 Sep: Using regular expressions to remove linefeeds and HTMLSing Cheng:"I met problems again when doing a guestbook. In the TEXTAREA of my guestbook form, when i enter First line then I submit my form and post the record into my database. But when it display, it will display as First line Second line Third line So, I am asking your help! Could you please tell me how to insert the line break code (<BR>) into each line of the text in the TEXTAREA before it is submitted into the datebase? Also, please do tell me how to remove HTML tags from my text before being submitted into the database. Thank you very much and I will very appreciate your help." Me: Both problems are easily fixed using regular expressions. To replace linefeeds with <br>, use this statement: sStr = sStr.replace ( /\n/g, '<br>' ); To remove all HTML from a string, try this: sStr = sStr.replace ( /<[^>]*>/g, '' ); |
|