Header Ads

Breaking News
recent

Regular expression to remove tag - regular expression to remove tags, special characters


Sometimes you need to remove the HTML tags or special characters, such as when searching for example.
When using the GET method to pass the search (Keywords) to the URL, if you only look for keywords in English is fine but if you are Vietnamese, sometimes you want to better their own URL, look over there a pro is to use regular expressions (Regular expression) for removing the tags or special characters.
Here, I use regular expressions with the JavaScript event Submit Button.
For example, in the event of your submit button call the JS function as follows:
<form action="http://bikip.vn" method="get" onsubmit="search(); return false;">
<input type="submit" name="submit" class="btn-tim" value="" />
</ Form>
When you submit will call the function Search () as below:
<script type="text/javascript">
function search () {
if ($("# keyword. ") val ()==")
{
$ ("# Keyword"). Val (");
$ ("# Keyword"). Focus ();
return false;
}
else
{
/ / Var key = ($("# keyword "). Val ());
var key = remove_tags ($("# keyword "). val ());
window.location = "http://ketoanmang.com/tim-kiem/" + key;
}
}
</ Script>
<script type="text/javascript">
remove_tags function (string_variable)
{
string_variable.replace string_variable = (/ [\?] + / g, ");
string_variable = string_variable.replace (/[<[^>] \ /*>]+/ g, "");
string_variable return;
}
</ Script>
In Function search () on the next call to the function remove_tags (). Remove_tag In this function we will use regular expressions to remove the special characters, the card ...
string_variable.replace (/ [\?] + / g, ");
string_variable.replace (/[<[^>] \ /*>]+/ g, "");
Then you do next, handling code was passed to remove the keywords depending on your card!
We hope that this brief article will help you do need or are looking at.
Goodluck!

No comments:

Powered by Blogger.