Disregard words in the input

Posted on

Question :

I would like to know how to override / disregard certain words placed by users in the input.

I have an input where the person should send me the URL of a website, in case they should send the url as site.com/image because I have a script that takes the rest of the information.

But it happens that people put things like site.com/image1.jpg, site.com/image2.jpg site.com/image3.jpg into the input and so error.

My question is how do I CANCEL CERTAIN WORDS IN INPUT like: imagen1.jpg, imagen2.jpg. So the weight can send the wrong link but the script would disregard these series of wrong words.
Or the escript could do a replace and substitute certain words with a blank space (tmb resolver)

I tried this script: link
But in practice it does not work when I click the submit button
sorry for the difficulty of expressing myself I’m starting programming.

My input code:

<form action="thumbs.php" method="post">
URL da thumb: <input type="text" class="restrict"  name="url"><br>
<input  type="submit">
</form>

    

Answer :

The form that came to mind is using ER(expressão regular) and method replace() .

<form action="" method="post">
URL da thumb:
<input type="text" class="restrict" name="url" value=""/><br/>
<input type="submit" onclick="replaceURL()" value="Enviar"/>
</form>
<script>
function replaceURL()
{ var inputURL = document.getElementsByClassName("restrict")[0].value;//captura o valor do input
var replaceurl = inputURL.replace(/.[d]{1,2}.jpg/, " ");//substitui o valor capturado pela "ER" por " "
/* "ER" explicação
* "." encontra o "." literalmente uma vez que ele é um operador é necessária a "" para escapar e torná-lo literal

Leave a Reply

Your email address will not be published. Required fields are marked *